MATLAB and C

D

Thread Starter

Deepa K

The C program I wrote is for opening a socket so that one pc can communicate with another pc. Now information is transferred between the two computers. The two computers are connected by a network. Meanwhile according to the data received in one computer, I have to invoke MATLAB and compute the control input in one computer and compute plant output in another computer. If anybody knows how to do this please help me...
 
Hello Sir,

I have an experiment to control remotely. The experiment is connected to a computer (server) connected to network. I have another
computer (client) by which I have to control my experiment. The controller has to be implemented on the client side. So basically it is client-server technology.

Both client and server are Linux machines. There is a C program in each of the 2 machines. First, I'll execute the C pgm in server. Then I'll execute the client program in client. A socket is opened in both the machines. So now data can be transmitted between client and server. The plant output will be transferred from server to client and accordingly, the control input has to be claculated. So here, I want to call the MATLAB program to compute the contol input. Again, if I simulate my plant, when the server pgm gets the contol input, I have to calculate the plant output. So again MATLAB has to be called. I want to use MATLAB so that I can view graphs.

If youhave the techniques to call MATLAB, please help me.


Thanking You,
Deepa.
 
P

Prabhat Ranjan

Deepa,
I do not fully understand your question, but if you want to invoke MATLAB subroutines from C, it is possible to do that, You need to have the
proper set of library. We had purchased such library. However, in case you need to do some calculations using matrices, it is possible to find such routines easily and avoid using MATLAB altogether, once you know exactly what needs to be done.

- Prabhat Ranjan

*******************************************************************************
Dr. Prabhat Ranjan e-mail : [email protected]
** SST Operation and Control Group Fax : 91-79-3269017
** ADITYA Tokamak Phone : (079)-3269001/02/03/04/05
Institute for Plasma Research, Bhat Village, Gandhinagar
Gujarat(India) - 382428
*******************************************************************************
 
C

Curt Wuollet

Ok that makes a lot more sense. What you have to do is determine when you have a complete dataset to run matlab against. It would be easiest if you were to write it to a file that can be passed to matlab as a parameter. I am assuming that Matlab can be run in a non-interactive mode with a dataset as a parameter. Once the file is written you can fork and exec matlab as a child process. This is slightly complex for a list message but basically you call fork this gives you two identical processes. You then check the PID to determine which process is which. The parent either waits or goes on with business. The child would call one of the family of exec system calls with matlab and the file as parameters. Matlab replaces the child process and runs.

Since it sounds like you would want results passed back from matlab,an easier alternative exists. It is the function popen() this is specifically intended for your situation. It executes a program with a pipe back to the parent and the parent simply reads the data from the pipe.

This is the very heart and soul of UNIX programming and the system calls and IPC's are the difference between a C programmer and a UNIX C
programmer. As such there are a wealth of books that describe what I'm talking about in more detail. I'm sure the information and examples are
available on the web also. To get much more specific. I would need some details. At first, I thought you were dealing with Windows and I don't do Windows I have no idea how they do this but I would expect they copied much of it. With Windows applications you would typically have no access and no source code and you would have to make do with some sort of wrappers.

Rest assured that what you want to do is mainstream programming for Linux and you can do it. I will try to help with specifics if you like. Do a man on popen, fork, exec, getpid, wait, read and write and see if it makes sense. A good book is "Linux Application Development" another is "UNIX systems programming". I do stuff like this fairly often.

Regards

cww
 
Top