?
Solved

Matlab and C/C++ communication program

Posted on 2011-02-25
4
Medium Priority
?
2,616 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Supports up to 4K resolution!

The VS192 2-Port 4K DisplayPort Splitter is perfect for anyone who needs to send one source of DisplayPort high definition video to two or four DisplayPort displays. The VS192 can split and also expand DisplayPort audio/video signal on two or four DisplayPort monitors.

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 …
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

719 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