Index in position 1 exceeds array bounds (must not exceed 3) For loop error

6 次查看(过去 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

回答(1 个)

Mitch Lautigar
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
  1 个评论
busra gogen
busra gogen 2022-5-9
Still same...
And tabledate contains only three rows now but I have more than three columns for each cell..
Index in position 1 exceeds array bounds (must not exceed 3).
Error in AlfaBetaArea (line 41)
if ( (4.5<=tabledata(j,6)) && (tabledata(j,6)<=4.9) )

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by