Solved

Matlab and C/C++ communication program

Posted on 2011-02-25
4
2,388 Views
Last Modified: 2016-03-02
hi there

I need recommendation for following scenario;

I have to write a program which  communicates between C/C++ and Matlab. C/C++ will act as server and matlab program shoul act as server. to be more specfic C/C++ program will generate
the numbers and send to the Matlab side and matlab will simultaneously plot these data.

best regards.
0
Comment
Question by:loopfinity
  • 3
4 Comments
 
LVL 32

Expert Comment

by:phoffric
ID: 34985419
I had asked this question at work, and I was told that Matlab supports TCP communication:
     http://www.mathworks.com/products/instrument/hardware/tcpip.html
and that I would have to purchase Mathworks' Instrument Control Toolbox option.

According to this link, Matlab can collect and plot data from a TCPIP server in real time.
0
 
LVL 6

Author Comment

by:loopfinity
ID: 34996940
Ok. thanks for links. but how can I integrated with C.
My C program will generate the numbers and write them on text files.
Matlab will interpret these numbers to plot.


could you please give solid example.
0
 
LVL 32

Accepted Solution

by:
phoffric earned 500 total points
ID: 34998396
I thought you were sending the data via TCP/IP, your zone selection.
here is an m-file that communicates with a server via TCP/IP:


% MATLAB example using TCP/IP (matlab_tcpip_example.m)
% This simple code example demonstrates how you can use MATLAB to exchange data 
% with a remote application not developed in MATLAB. This code example is taken
% from a MATLAB Digest technical article written by Edward J. Mayhew from 
% George Mason University.  While HTTP was used as the higher-level protocol in 
% this example, you can use other protocols, as was the case in the project. 
% MATLAB supports TCP/IP using Instrument Control Toolbox.  Requires MATLAB and 
% Instrument Control Toolbox.  
%
% On line 14, substitute "www.EXAMPLE_WEBSITE.com" with an actual website with
% which you wish to communicate.

% Create TCP/IP object 't'. Specify server machine and port number. 
t = tcpip('www.EXAMPLE_WEBSITE.com', 80); 

% Set size of receiving buffer, if needed. 
set(t, 'InputBufferSize', 30000); 

% Open connection to the server. 
fopen(t); 

% Transmit data to the server (or a request for data from the server). 
fprintf(t, 'GET /'); 

% Pause for the communication delay, if needed. 
pause(1) 

% Receive lines of data from server 
while (get(t, 'BytesAvailable') > 0) 
t.BytesAvailable 
DataReceived = fscanf(t) 
end 

% Disconnect and clean up the server connection. 
fclose(t); 
delete(t); 
clear t

Open in new window

0
 
LVL 32

Expert Comment

by:phoffric
ID: 34998542
>> My C program will generate the numbers and write them on text files.
Then if your matlab can access the files directly, then you can use fscanf to read the files:
     http://www.mathworks.com/help/techdoc/ref/fscanf.html
(has code examples to read file)
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question