how to save the value of each iteration in a loop for later use in the program?
    조회 수: 10 (최근 30일)
  
       이전 댓글 표시
    
My code is:
a=input; b=input;
while(1)
c=statement;
 if(x>0) 
s=a-c;
a=altered a;
 else
break;
 end
end
I want each value of s to be known for later use.
댓글 수: 0
답변 (2개)
  Julia
      
 2015년 4월 10일
        Hi,
use an additional counter and an array/vector for s. s will change its size in every iteration and Matlab will show you a warning. If you have an upper bound for the loop iterations I suggest to use it for preallocation.
댓글 수: 3
  khan
 2015년 4월 10일
				initialize counter_ind =1; before while loop. modify your statement to this
   s(counter_ind) = a-c; 
   counter_ind = counter_ind+1;
  khan
 2015년 4월 10일
        may be your data in a-c is bigger than a value. So you have to use according to your data i.e. a and b. i dont know exactly what do you have in a and c. but i think this will save anything.
s{counter_ind} = a-b;
댓글 수: 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!


