Index in position 1 exceeds array bounds (must not exceed 3) For loop error
2 次查看(过去 30 天)
显示 更早的评论
EventsDateIncludedforArea is 1x6 cell and and each array in it has 6 columns. Matlab gives me error of exceeds array bounds in line 38 but I can't notice my error. Can anyone help me? Here is my code and matrix is in that figure
36 for i=1:length(EventsDateIncludedforArea)
37 for j=1:length(EventsDateIncludedforArea{i})
38 if (4.5<=EventsDateIncludedforArea{i}(j,6) && EventsDateIncludedforArea{i}(j,6)<=4.9)
39 index1{i}=[EventsDateIncludedforArea{i}(j,6),EventsDateIncludedforArea{i}(j,1)];
40 end
41 end
42 end
0 个评论
回答(1 个)
Mitch Lautigar
2022-5-9
The issue you have is that your second for loop is looking in the same indices as your first for loop. Here's my suggestion:
index1 = []; %pre-declaration
for i=1:length(EventsDateIncludedforArea)
tabledata = EventsDateIncludedforArea{i};
[a,b] = size(tabledata); %a is rows, b is columns
for j=1:b
if ( (4.5<=tabledata(j,6)) && (tabledata(j,6)<=4.9) )
index1{i}=[tabledata(j,6),tabledata(j,1)];
end
end
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!