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

5 views (last 30 days)
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

Answers (1)

Mitch Lautigar
Mitch Lautigar on 9 May 2022
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) )
  1 Comment
busra gogen
busra gogen on 9 May 2022
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) )

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!