Index exceeds number of array elements in for loop
1 回表示 (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
KALYAN ACHARJYA
2021 年 1 月 24 日
編集済み: KALYAN ACHARJYA
2021 年 1 月 24 日
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?
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!