Wrong code. Does not get into the while loop.
1 view (last 30 days)
I wrote a code which is not yielding what I epected. In the mat file, I have a variable called "UntitledVoltage" and it is the voltage gathered from a power relay. It looks like 28 28 28 28 28 0 0 0 0 0 0 28 28 28 28 28 0 0....(a lot of values here, and at the end the voltage decreases like:) 20 20 20 20 20 0 0 0 0 0 20 20 20 20 20 0 0 0 0 0.
So here it is the code I wrote:
s=k; %so the while does not occur after a consecutive 1 and 2nd condition
occurs as the k reiniciates after the while loop.
disp(k) It displays as it is supposed but it seems the conditions of the while are never met
while UntitledVoltage(k)>15 && UntitledVoltage(k)<26 && k>=s+n %3rd condition achieves what it was said before.
disp (OpenVoltage) *DOESN'T SHOW ANYTHING*
I suspect it has something to do with the 3rd condition of the while loop. I just wanted to eliminate the "reset" capability of the "K" once it finish the for loop, so the next voltage value that met the first two conditions is not taken into account again.
Any help will be appreciated!!
Daniel Shub on 24 Jul 2013
When k is equal to 2, s is equal to 2 and n is equal to 0. If UntitledVoltage(2) is not between 15 and 26, then you skip the while loop and then n gets set to 1. Then when k is equal to 3, s is equal to 3 and n is equal to 1 so k>=s+n is not true and you skip the while loop no matter what UntitledVoltage(3) is. This repeats until the your for loop ends.