How to have variables displayed in workspace after every while loop iteration?
조회 수: 30(최근 30일)
I have a while loop in which my variables are only stored in the workspace after the entire loop is completed. Is there any way that I can store the variable in the workspace after each iteration of the loop, because I need to use these values while the loop is still running. Thank you!
Star Strider 2014년 11월 12일
The easiest way (without seeing your code) is to initialise a counter before the loop, increment it within the loop, and subscript the variables calculated in the loop:
k1 = 1;
a(k1) = some_expression;
b(k1) = some_other_expression + a(k1);
k1 = k1+1;
Here, â€˜aâ€™ and â€˜bâ€™ will be available as vectors at the end of the loop, and available to each other within the loop. Thatâ€™s as specific as I can get.
Andrew Reibold 2014년 11월 12일
편집: Andrew Reibold 2014년 11월 12일
Not sure if you are having issues with the worksplace, or if you are actually trying to say you are having trouble displaying values to the screen while running the program
Instead of using
out(length(out) + 1) = str2num(value)
Can you use...?
out(i) = str2num(value)
Then, can you use...?
Or if you want to keep track of which iteration you are on also,
disp(['Iteration ',i,'- Out value of ',out(i)])