Solved

Matlab and C/C++ communication program

Posted on 2011-02-25
4
2,484 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IP address incorrect 8 103
Please explain C language error codes ? 5 52
Fill Null values 5 55
Excel Macro update each line based on another worksheet 2 59
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Creating an OSPF network that automatically (dynamically) reroutes network traffic over other connections to prevent network downtime.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

751 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