Hi all,
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:
clear load('Voltage1.mat')
Arc=zeros(numel(UntitledVoltage),1);
MeanVolt=zeros(numel(UntitledVoltage),1);
OpenVoltage=zeros(100,1);
s=0;
n=0;
t=1;
x=1;
m=1;
for k=2:numel(UntitledVoltage)
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.
OpenVoltage(x)=UntitledVoltage(k); disp (OpenVoltage) *DOESN'T SHOW ANYTHING* k=k+1; x=x+1; end; OpenVoltage=OpenVoltage(setdiff(1:numel(OpenVoltage),x+1:numel(OpenVoltage))); MeanVolt(m)=mean(OpenVoltage); Arc(k)= MeanVolt(m); t=t+1; m=m+1; n=x; x=1; end;
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!!
Many thanks
Sergio.
Best Answer