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

5 vues (au cours des 30 derniers jours)
busra gogen
busra gogen le 9 Mai 2022
Modifié(e) : busra gogen le 10 Mai 2022
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

Réponses (1)

Mitch Lautigar
Mitch Lautigar le 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 commentaire
busra gogen
busra gogen le 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) )

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by