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!