Index exceeds number of array elements in for loop

1 visualización (últimos 30 días)
Owen Gray
Owen Gray el 24 de En. de 2021
Editada: KALYAN ACHARJYA el 24 de En. de 2021
I'm trying to replace 0 with NaN if it is present at the 2nd or 6th element of a column vector. I also need to replace with NaN if there are 9 consecutive zeros, or two NaNs if there are 12 consecutive zeros. I then try to remove all the remaining 0s.
RTa = cell2mat(Rxtcell);
if RTa(2) == 0
if RTa(6) == 0
RTa(6) = NaN
end
RTa(2) = NaN;
end
for n = 1:length(RTa)
X = RTa(n:n+8);
X2 = RTa(n:n+12);
Y = [0;0;0;0;0;0;0;0;0];
Y2 = [0;0;0;0;0;0;0;0;0;0;0;0;0];
if X==Y
if X2==Y2
RTa(n+1) = NaN
end
RTa(n) = NaN
end
end
RT1 = RTa(RTa~=0);
Gives the error
Index exceeds the number of array elements (241).
Error in RTscript (line 11)
X2 = RTa(n:n+12);
If I run script or copy-paste and run in workspace respectively.

Respuesta aceptada

KALYAN ACHARJYA
KALYAN ACHARJYA el 24 de En. de 2021
Editada: KALYAN ACHARJYA el 24 de En. de 2021
Error message providing sufficient reason for error
As you are trying to access RTa upto n+12, here n is max length(RTa).
Example:
A=[3,4,5,6]
Here length of A is 4, now if you wish to access the data upto 4+any value, is their any sense?

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by