Plotting results in array of a while loop
2 views (last 30 days)
I want to iteratively plot the results of my while loop, however, I end up with a blank graph or an error.
Here is the code:
while Vlow < 450
out = solution(solution<0.35 & solution>0.129);
if I1 > I2 then
Any help would be greatly appreciated,
Adam Danz on 22 Jun 2020
Edited: Adam Danz on 22 Jun 2020
As the error message indicates, a subscript must be a real, positive integer or logical.
On the first iteration, i equals 0 which does not fulfill these requirements. 0 is not positive and it's not a logical value. So, when you index Y(i), or, Y(0), you get the error.
Instead of initializing i=0, set it to 1, i=1;
More importantly, the while-loop is defined by the value of Vlow but this value never changes within the while-loop so the while-loop will never end. Vlow will always be less than 450 because its original value is 350 which never changes within the loop.
Perhaps you meant to include something like this at the end of the while-loop.
Vlow = X(i);
If that's the case, then you could replace the while-loop with a for-loop since you know ahead of time the number of iterations. The number of iterations will be the number of values in
values = 350 : 20 : 450;