View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Collect and plot data from an instrument in real time

3.0 | 10 ratings Rate this file 203 Downloads (last 30 days) File Size: 2.33 KB File ID: #25519 Version:
image thumbnail

Collect and plot data from an instrument in real time



07 Oct 2009 (Updated )

Real time data collection & plotting using query based instrument interactions.

| Watch this File

File Information

This MATLAB(R) script generates a real time plot of voltage values collected from an Agilent(TM) 34401A Digital Multimeter over the serial port(RS232). The data is collected and plotted until the predefined stop time is reached. This example also demonstrates automating a query based interaction with an instrument while monitoring the results live.
This script can be modified to be used on any platform by changing the serialPort variable.

On Linux: serialPort = '/dev/ttyS0';
On MacOS: serialPort = '/dev/tty.KeySerial1';
On Windows: serialPort = 'COM1';

The script may also be updated to use any instrument/device to collect real time data. You may need to update the SCPI commands based on information in the instrument's programming manual.

To generate a report of this entire script, you may use the PUBLISH command at the MATLAB(R) command line as follows:


MATLAB release MATLAB 7.8 (R2009a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (17)
12 Dec 2016 Chris

Chris (view profile)

All this zip file contains is a blank license.txt file.

15 Nov 2016 Gourish

26 Oct 2016 Jibran Shahid

There is not code inside

04 Oct 2016 Nguyen Thanh Duoc

Thanks a lot.

Comment only
16 Apr 2016 Shaymon Alvarez

22 Oct 2014 Henri A

Can anyone kindly take a look at look my following errors. What should I do to get this to work please?

>> real_time_data_plot
Index exceeds matrix dimensions.

Error in real_time_data_plot (line 34)
serialObject = serial(serialPort);

Comment only
29 Sep 2014 NguyenTung

Thanks a lot.
I test your code, and it's okay.
with condition i change:
voltage(count) = fscanf(serialObject,'%f',1); %#ok<SAGROW>

I don't now why? but result is good.

Thank a again.

Comment only
02 Apr 2014 Stuart

Stuart (view profile)

Great code, nice and neat. Just wondering if you know whether you can run this concurrently with other processes, say, in a GUI? I want to have this logging every few seconds and in between, pass control back to allow other processes to run.
Great work

10 Feb 2014 An Nguyen

09 Apr 2012 Andrew

Andrew (view profile)

Hello Ankit,

Thank you very much for sharing this with us. I'm trying to read in sonar data via UART continuously over the serial port. I am having speed issues, however, after a certain amount of time.

Would you happen to know if this is a buffer issue? There doesn't seem to be any active cleaning as count increases. I tried a quick fix to reset count back to 1 after 200 iterations which does update correctly but the speed issue still persists.

Any insight would be greatly appreciated!

Comment only
30 Mar 2012 saranya

and..sir....i dunno to decide...if i should show the three heat variations in a single graph or to create three separate graphs to show induvidual variation...please help me to finish the code sir...

Comment only
21 Feb 2012 Ying Zhou

Thanks for ur work. It's very useful. I have a pressure sensor to measure air pressure. I use Arduino uno to do ADC and connect to PC. Send data trough serial port to PC. Just made a little change of ur code I got real-time plot of my sensor data successfully.

21 Feb 2012 Ying Zhou

21 Feb 2012 Ying Zhou

08 Oct 2010 Ankit Desai

You are getting that error since the fscanf on the serial object did not return any data. You might want to put in a check to make sure you are getting data in each iteration. Hope this helps.

Comment only
27 Sep 2010 Christian Franco

Hallo and thank you for your work. When i run the file it prompts an error that said

??? In an assignment A(I) = B, the number of elements in B and
I must be the same.

Error in ==> real_time_data_plot at 81
voltage(count) = fscanf(serialObject,'%f'); %#ok<SAGROW>

thank you

Comment only
17 Mar 2010 Diego Barragán

Diego Barragán (view profile)

01 Sep 2016

Updated license

Contact us