Info
この質問は閉じられています。 編集または回答するには再度開いてください。
For Loop (or if-condition) is ignoring the first value
1 回表示 (過去 30 日間)
古いコメントを表示
Hello everybody, like I mentioned I´ve got the problem, that the first value is ignored (the first value of the matrix 'auftraege'):
for j=1:n_pop
for i=1:n_auf*n_lkw
for k=1:n_auf
if matrix(j,i)==auftraege(k,1)
matrix(j,i)=auftraege(k,2);
end
end
end
end
2 0 0 0 3 0 0 5 1 4
1 0 0 0 4 0 0 2 1 1
If I use this code and set k to k=2:n_auf I get the same solution as mentioned above.
for j=1:n_pop
for i=1:n_auf*n_lkw
for k=1:n_auf
if matrix(j,i)==auftraege(1,1)
matrix(j,i)=auftraege(k,2);
end
end
end
end
0 0 5 4 0 1 0 3 0 2
0 0 5 4 0 4 0 3 0 2
As you can see: When I put the number 1 directly into the if condition, the solution for the 1 is correctly. After these tests I think the problem is that the for loop starts with k=2 and not k=1. Do you think I´m right with my guessing? Or do you even got a solution?
Thanks everybody
0 件のコメント
回答 (0 件)
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!