Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Photo

Plotting real time charts


  • Please log in to reply
1 reply to this topic

#1 tee-banks

tee-banks
  • Members
  • 2 posts

Posted 25 July 2014 - 04:57 AM

hi i am using u12 labjack to send out 5 and 0v alternately using the state of  two switches as digital inputs. I want to be able to plot the alternating voltage against time in real time as the while loop scans the program. This is the program i have, any suggestions

while 1
%Setting analog output
analogOut0 = 5.0;
analogOut1 = 5.0;
%Reading Reed switch from Digital Input IO0
channel = 0; %IO0
readD = 0; %Read IO line (>0 for D line)
state = 0; %Returned state (>0 = high, 0 = low)
[errorCode, idnum, state] = lj.LabJack.EDigitalIn(idnum, demo, channel, readD, state);
if state<0
    state=0
elseif state>0
    [errorCode, idnum] = lj.LabJack.EAnalogOut(idnum, demo, analogOut0, analogOut1);%Set both AO0 and AO1 to 5V
end
disp(['IO' num2str(channel) 'state' num2str(state)])
%Setting analog Output
analogOut0 = 0.0;
analogOut1 = 0.0;
%Reading Reed switch from Digital Input IO1
channel = 1; %IO0
readD = 0; %Read IO line (>0 for D line)
state = 0; %Returned state (>0 = high, 0 = low)
[errorCode, idnum, state] = lj.LabJack.EDigitalIn(idnum, demo, channel, readD, state);
if state<0
    state=0
elseif state>0
    [errorCode, idnum] = lj.LabJack.EAnalogOut(idnum, demo, analogOut0, analogOut1);%Set both AO0 and AO1 to 0V
end
disp(['IO' num2str(channel) 'state' num2str(state)])
end
pause(2.0)
 



#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 25 July 2014 - 10:25 AM

You'll want to look at the MATLAB documentation for charts and plotting:

 

http://www.mathworks...d-3d-plots.html

 

You can get the current time with one of the data/time functions:

 

http://www.mathworks...operations.html

 

As for plotting the voltage, one way would be to save the AO current voltage values and at the end of the loop (before pause) get the current time then plot the current voltage against current time. One way to save the AO voltages would be to only set analogOut0 and analogOut1 variables before you set the AOs in your "elseif state>0" chunks of code. That way at the end of the loop you know the current voltages and if your loop iteration doesn't set the voltage you know the last set voltages.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users