How to fix my for loop to continue to the next value in the list when condition is false?

2 views (last 30 days)
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
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.
Amanda S
Amanda S on 7 Jul 2020
It says:
>> whos Besparingslistan
whos Kund_i_tur
Name Size Bytes Class Attributes
Besparingslistan 169x3 4056 double
Name Size Bytes Class Attributes
Kund_i_tur 13x1 104 double
And i understand that the varibles are different sizes but I dont know how to do it any other way since I want to loop through Besparingslistan with "forstakund" as row i column 1 and "andrakund" as row i column 2. forstakund and andrakund are supposed to change value as the loop iterations goes forward.
Kund_i_tur is supposed to represent a vector that eventually will be updated and show which routes that the customers 1-13 is part of (the whole code is based on the Clarke & Wright savings algoritm), therefore I dont know how to do it another way...

Sign in to comment.

Answers (0)

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!