필터 지우기
필터 지우기

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

조회 수: 3 (최근 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