Something is wrong with this simple code.

Hi, I am quite new here and I am trying to write a code. We have collected data from two channels.
One is actuation count of a relay which is like 0001111111111111111111111111111111111111111111111122222222222.... and a voltage signal that is like 24,24,23,5,3,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,10,20,24,24,24,...
I want to analyse the data, and count how many samples occur since the actuation count changes (in the code I compare it to a variable named "x")and the voltage data reaches 0. then I multiply the number of samples for the time of the sample rate to calculate the time it takes to reach 0 Volts totally. Then I add these values to an array "tclosearray". I will appreciate any help.
It says it is busy so I guess a loop is running nonstop.
This is the code:
tclosearray=[];
y=0;
x=0;
for k=1:30000
if UntitledActuation_Count(k)~=x
while UntitledVoltage(k)>=0
if k<= 30000
y=y+1;
k=k+1;
end;
end;
tclose=y*0.01;
tclosearray=[tclosearray;tclose];
y=0;
x=UntitledActuation_Count(k);
end;
end;

4 Kommentare

David Sanchez
David Sanchez am 27 Jun. 2013
Your guess has to be right. You have to be within an infinite loop. What does the function UntitledActuation_Count do?
Most likely the loop-break condition is never fulfilled. Make your code to present some data in command window to debug it.
Sergio
Sergio am 27 Jun. 2013
Hi David! UntitledActuation_Count is an array of data collected from a relay which works as a switch here. (Open/close)Do you know how to show some data in the command window?
(Sorry the GMAIL didn-t tell me you answered me!)
Thanks
Sean de Wolski
Sean de Wolski am 27 Jun. 2013
Bearbeitet: Sean de Wolski am 27 Jun. 2013
@Sergio,
use something like:
disp(UntitledVoltage(k))
Sergio
Sergio am 27 Jun. 2013
Thank you for the advice

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

David Sanchez
David Sanchez am 27 Jun. 2013

0 Stimmen

Make sure the data array
UntitledVoltage(k)
contains some negative data, otherwise the while loop will go on for ever. (see advice given by Sean de Wolski in his comment)

1 Kommentar

Sergio
Sergio am 27 Jun. 2013
This is the new code. Yes, it didn-t have 0, or negative data, so I changed it for >0.2 which is good after seeing the data. My bad. However, it stills say it is busy and doesn-t create the array with the solutions :(
tclosearray=[];
y=0;
x=0;
for k=1:numel(UntitledVoltage)-1
if UntitledActuation_Count(k)~=x
while UntitledVoltage(k)>0.2
if k<numel(UntitledVoltage)-1
y=y+1;
k=k+1;
end;
end;
tclose=y*0.01;
tclosearray=[tclosearray;tclose];
y=0;
x=UntitledActuation_Count(k);
end;
end;

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by