Using 'If statements' and 'for loops', my matrix isn't populating properly!
조회 수: 1 (최근 30일)
이전 댓글 표시
jumps = zeros(10,5);
for i = 1:10
for j = 1:5
if top_currencies_vol_change(i,j) < 0.75
jumps(i,j) = -1;
return
else
if top_currencies_vol_change(i,j) > 1.25
jumps(i,j) = 1;
return
end
end
end
end
Using the above code, the matrix populates until the first condition of one of the if statements is satisfied, e.g.
0 0 0 0 0
0 0 0 1 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
when I want it to continue populating until the entire matrix has been completed. Any idea why it just stops after the first success?
댓글 수: 0
채택된 답변
kjetil87
2013년 7월 23일
its because of the return command.
example
for i=1:10
disp(i);
return;
end
% correct version
for i=1:10
disp(i);
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!