How to fix my for loop to continue to the next value in the list when condition is false?
2 views (last 30 days)
Show older comments
Hi,
Could anyone help me with how I could fix my code so it continues to check the next value in the list (Besparingslistan) if the condition in the IF-statement is false?
Also, right now I get the error "Index exceeds the number of array elements (13)." How can I fix it?
(The "Besparingslistan" is a list with the size 169x3 built up with different combinations of 13 different customers in the first two columns and a savingsvalue in the third column. While Kund_i_tur and Turkonfig are column vectors with the customers, aka (1:1:13). )
f = size(Besparingslistan,1);
a = size(Besparingslistan,2);
for forstatur = 1:f
for andratur = 1:a
if Kund_i_tur(f)~= Kund_i_tur(a)
Turkonfig = {f a};
end
end
end
4 Comments
Image Analyst
on 6 Jul 2020
What does this show in the command window:
whos Besparingslistan
whos Kund_i_tur
It seems like either (the poorly named) f or a is larger than the length of Kund_i_tur.
Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!