Looping through index number + 1
Ältere Kommentare anzeigen
Hello, say I have a cell array called 'group' and I want to loop to do a specific calculation which is the following:

In this case, i goes from 1 to 15 and I am calculating the norm between each cell subarray, 1st row.
So when i = 15, where my code has i+1 this would be 16 and it would exceed the index number of array elements.
What would be the best way to avoid this issue? Using an if statement when i == 15?
Thanks.
Akzeptierte Antwort
Weitere Antworten (1)
Antoni Garcia-Herreros
am 28 Mär. 2023
Not exactly sure what you are trying to do but, why do you want to loop through all 15 cells? isn't it enough to loop through 14?
for i=1:size(group)-1 % This only loops 14 times
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!