File Exchange

image thumbnail

MATLAB TCP/IP - code example

version (1.29 KB) by Steven Kolak
MATLAB with TCP/IP - code example


Updated 01 Sep 2016

View Version History

View License

MATLAB supports TCP/IP communication using Instrument Control Toolbox.
This MATLAB code example shows you how to exchange data with a remote application using TCP/IP. This example is taken from a MATLAB Digest technical article written by Edward J. Mayhew from George Mason University.
Learn more about using MATLAB with TCP/IP communication at:

Cite As

Steven Kolak (2021). MATLAB TCP/IP - code example (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (27)

Aldo Borrego

I need to communicate Matlab with a Click PLC using Modbus TCP. Has someone done it before?

zahid mehmood

Gus Lott

Did not work.


FYI - someone named Steven Michael wrote an excellent TCP/IP library for MATLAB that allows easy exchange of MATLAB variables including structs! As far as I can tell, most discussions of MATLAB TCP/IP don't know about this code and don't provide a solution for exchanging types like structs. It took me a long time to find this, not sure why it's not more widely known. Please share!

Usman Qadir

Hi i have a built in tcp server in one of my programs. I want to transmit data from my software to matlab using tcp. How can i query the server for returning the value of a specific variable ? which set of commands should i use ?


very good


Xiaomin Zhou







How to transfer a variable is a string?
example: varable data

I written: fprintf(tcpServer,data,'String')
But it show error:
Error using icinterface/fprintf (line 130)
FORMAT must be a string.

Error in tcp (line 5)

How can I fix it?

Avinash Parnandi

Very good program for beginners.

ibrahim khalil

I have tried to use this example too but it didn't work. Try to write your own S-Function with a Client or a Server.

Benea Catalin

Question: How can I send data from matlab simulink with instrument control toolbox tcp/ip send/receive blocks , between 2 computers. What do I need to configure actually receive something on the remote computer


Can somebody pls let me know whether this "Instrumentation tool box" or "tcpip" function in MAtlab can be ued to read data received by the ethernet port?

Thank you.

Ricardo Correia

Hello! Can i transfer data on matlab, from one session to other?
Is it possible with this code? I want to transfer a wav file from a server to a client (on matlab).
Thanks for your help.



has anyone an example which communicates with the Visual Studio (c#, Vb.Net,...)?

ibrahim adnan


Gundi Can


I build a socket communication with Matlab and VS2003. My question is, if I send data from VS (server) to Matlab-Client, the fscanf operation needs a lot of time. I have to terminate the server programm. In Matlab Command window prompts the warning:Warning: A timeout occurred before the Terminator was reached.
Error in ==> icinterface.fscanf at 196
out = fscanf(igetfield(obj, 'jobject'), totalSize);

Error in ==> scope_mod at 33
rcvData = fscanf(t);

Does somebody have any suggestion?

Thanks a lot!

savita sheoran

Filipe Ieda Fazanaro

Nhan Nguyen

Hideaki Okazaki

Bill O'Shea

This is a "starter" example, but it does show you how to easily transfer data with MATLAB using TCP/IP.

MATLAB Release Compatibility
Created with R2006a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!