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

1 次查看(过去 30 天)
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 个评论
Image Analyst
Image Analyst 2020-7-6
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 2020-7-7
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...

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by