Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Matlab stuck at Warning about Integers

1 visualización (últimos 30 días)
Mark Dawnson
Mark Dawnson el 16 de En. de 2019
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hi people,
I need help. I'm running a code and I am getting stuck at line 51 that reads:
sortedData = sort(cutData(tstart:tend));
baseline = median(sortedData(1:((0.2)*length(cutData(tstart:tend)))));
deltaF(i) = (cutData(i) - baseline)/baseline;
This is the message I keep getting:
> In scrapAnalysis (line 51)
Warning: Integer operands are required for colon operator when used as index
  1 comentario
Walter Roberson
Walter Roberson el 16 de En. de 2019
length(cutData(tstart:tend) is going to be the same as tend-tstart+1 . But suppose that does not happen to be an exact multiple of 5, so 0.2 times the value does not turn out to be an integer?

Respuestas (3)

Fangjun Jiang
Fangjun Jiang el 16 de En. de 2019
With this, do you get it?
>> a=rand(1,100);
>> b=a(2:10);
>> c=a(2:0.9:10);
Warning: Integer operands are required for colon operator when used as index.

Star Strider
Star Strider el 16 de En. de 2019
Without knowing more about ‘cutData’, it’s difficult to provide a specific solution. Subscripts must be integers greater than 0, or logicals
Assuming that ‘t’ is your time vector associated with ‘cutData’, try this:
tstart = ...;
tend = ...;
idx1 = find(t >= tstart, 1, 'first');
idx2 = find(t <= tend, 1, 'last');
sortedData = sort(cutData(idx1:idx2));
Something like that should do what you want. You will have to experiment with it with your code.

Mark Dawnson
Mark Dawnson el 17 de En. de 2019
Thanks for all the answers. I'll try these and let you know !
  1 comentario
Star Strider
Star Strider el 17 de En. de 2019
It would also help to know the complete error message. (Please copy all the red text in your Command Window and paste it to a Comment here).
There are at least two lines that could be throwing that error. We have no idea which one it is.

La pregunta está cerrada.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by