Filter löschen
Filter löschen

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

7 Ansichten (letzte 30 Tage)
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

Antworten (1)

Mitch Lautigar
Mitch Lautigar am 9 Mai 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) )
index1{i}=[tabledata(j,6),tabledata(j,1)];
end
end
end
  1 Kommentar
busra gogen
busra gogen am 9 Mai 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) )

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by