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 a TCPIP server in real time

5.0 | 7 ratings Rate this file 74 Downloads (last 30 days) File Size: 2.22 KB File ID: #27290 Version:
image thumbnail

Collect and plot data from a TCPIP server in real time



19 Apr 2010 (Updated )

Obtain real time data from a TCPIP object using Instrument Control Toolbox and visualize it live.

| Watch this File

File Information

This example demonstrates how to automatically read a set number of data bytes as and when they are available. This MATLAB® script also generates a real time plot of streaming data collected from the TCPIP server.
The script may be updated to use any instrument/device/TCPIP server to collect real time data. You may need to update the IP address and port.

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


Required Products Instrument Control Toolbox
MATLAB release MATLAB 7.9 (R2009b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (23)
10 Jan 2017 Piotr Budzynski

zip file is empty
license.txt 0 bytes

Comment only
04 Oct 2016 Nguyen Thanh Duoc

18 Jul 2016 meng meng

Thinks for your work,I'm looking for this kind of example...

23 Oct 2015 Ankit Desai

Hi Laura,

I am not sure if I can correctly answer your question without much insight into the code. However, these reference materials might help:


It might be that for what you would like to do, you need to update some other property.

All the best!

Comment only
11 Sep 2015 Laura Lippi

Hello Ankit,
I have a problem to plot data. When I try to plot data, I use this part of code:


but it doesn't plot my data ax, but it refreshes the data' values only on the y-axis of the plot.
Thank you very much for your help!

Comment only
16 May 2014 John Booker

14 Apr 2014 Fan

Fan (view profile)

02 Jan 2014 Chau Nguyen

01 Dec 2012 jaeankr

09 Aug 2012 che adil

hello ankit,
I tested your code on an ip camera to receive streaming on matlab, but it does not work?!
I do not know where the problem,
at first it gave me an error at line 66 in function "fopen" and there I change the entry "localhost" with the ip address of the camera with a port "8001" but it gave neither error nor result!
knowing that the camera is normally secured by password, what is the solution in your opinion?

Comment only
01 Aug 2012 Luis Celi

It doesn’t plot anything! I think that doesn't work because it isn’t a numeric data... I proof that making a ping to another computer and doesn’t plot anything How I can try? Thanks...

Comment only
15 Apr 2012 amit pathania

I want to read live video stream from my media server over LAN in there any way to do this? Actual setup is like this: There is survelliance equipment.Using TV tuner card and media encoder,we are streaming it over LAN to other users. Users can enter url(IP address of media server and port number) in their media player and can view the live feed. We want to read this feed in MATLAB so that we can carry out image processing on this stream.

Comment only
11 Apr 2012 amit pathania

hi can I use this code to read live video stream from Media Server?

Comment only
11 Apr 2012 amit pathania

hi can I use this code to read live video stream from Media Server?

Comment only
10 Feb 2012 Ankit Desai

Hi Abhishek,

You might have to replace the "~" with a variable name. The "~" is used to denote a variable that is never used in the code.

The callback function always takes in parent object and event as the first two arguments. However, since I am not using the event variable in the callback function, I replaced it with "~". Once you put a variable name in it's place, it should work fine.

Hope this helps,

Comment only
10 Feb 2012 Abhishek

Hi Ankit,
I am running your code in the version number R2008a.
I got the following error
Error: File: real_time_data_stream_plotting.m Line: 70 Column: 43
Unexpected MATLAB operator.

Please clarify...


Comment only
31 Aug 2011 Rubens Almiron

Hello Ankit,
Can I use this program in Matlab version 2007b?

Comment only
11 Apr 2011 Mohammad

Hi Ankit,

Thanks for your useful script. I got it work; however I still do not know how to get the data which are being read by the TCPIP server.
In other words, using your file, I can stream and plot all those data, but I need to demonstrate more results, so I require the data at each instant. I am wondering how I can access those data?


Comment only
24 Jan 2011 Ankit Desai

Ghani, the error might be due to corrupted path. Try to reset MATLAB path and see if that works.

It might also give you this error if you have created your own plot function which takes different number of inputs. Hope this helps.

Comment only
06 Jan 2011 Ghani Amna

Hi... I also ran this code,but it's showing error.

??? Error using ==> plot
Too many input arguments.

Error in ==> real_time_data_stream_plotting at 51
plotHandle = plot(axesHandle,0,'-y','LineWidth',1);
Any Help...?

Comment only
12 Oct 2010 John Luthar

That worked great!

I ran into another problem I can't figure out.
The tcpip object has a communication state that shows closed/open.

I'm currently using Matlab as a client connected to a server. If the server goes down, the communication state (connection.status) doesn't change from open -> closed.

Once it connects, the status doesn't seem to change again. How would I check if the connection ever went down?

08 Oct 2010 Ankit Desai

You might also have to update the TCPIP object's InputBufferSize and OutputBufferSize properties along with bytesToRead variable in the program to the desired number. Hope this helps.

Comment only
10 Sep 2010 John Luthar

Is it possible to read more than 500 bytes on the call-back?
I can't seem to get that working.

Comment only
01 Sep 2016

Updated license

Contact us