While loop
조회 수: 2 (최근 30일)
이전 댓글 표시
Hoping somebody could help me fix my while loop.
Whilst the output to a function Convergence == 0 i want the while loop to continue to iterate, producing an output matrix R_2, and also updating the run_number to run_number + 1. It's not necessary to store the previous matrices, if it's faster to run then the matrices could be replaced.
Here's what i have so far.
R_2 = %%not sure what goes here.
Conv = 0; %initially convergence criteria = 0
run_number = 1;
R_2{run_number} = R_2;
while Conv == 0
R_1 = %%%%function producing R_!;
Radius = %%function producing
R_2{run_number} = %function of R1 and Radius
Conv{run_number} = Conv(R_2{run_number});
run_number = run_number+1;
end
Thanks a lot
댓글 수: 0
답변 (1개)
Walter Roberson
2012년 5월 3일
Conv{1} = 0; %instead of Conv = 0;
while Conv{end} == 0
and use
Conv{run_number} = Conv{R_2{run_number}}; %instead of Conv()
However, please examine this statement more carefully:
Conv{run_number} = Conv{R_2{run_number}};
On the first iteration, Conv{1} is the only thing that exists, so if R_2{1} is not exactly 1 then you would be accessing out of bounds. So R_2{1} must be 1, and you are then setting Conv{1} = Conv{1} and that was initialized to 0. Second iteration, Conv{1} is still the only thing that exists, so R_2{2} must be 1, and you are setting Conv{2} = Conv{1} which is 0. Third iteration, the existing Conv{1}=0 and Conv{2}=0 are what exists, so Conv{3}=0. By induction, you are going to continue the loop with 0's until you run out of memory.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!