Page 1 of 1

generating command line output from inside matlab

Posted: 2011/12/14 20:18:48
by mattmer
Hello,

I am a centos 5 user and I am running matlab R2011a. I don't think my question is version specific at all.

I am running a markov chain monte carlo (MCMC) simulation that compares real data to my simulated data. The MCMC front end calls a program that generates the simulated data. This simulated data is returned to the MCMC program itself and then a subtraction of the simulated data from the real data is performed. The MCMC front end does this about 10000 times during a single run, so speed of the program being called by the MCMC is essential. Usually the subroutine called by the MCMC program is written in fortran. I am not particularly fortran savvy, so I was exploring options of using a matlab executable instead. Matlab has the option to open a file and write results to it, but this is obviously a bad idea, as running a simulation, then opening a file, writing to it, then closing it, followed by opening it with my MCMC front end would impose a huge overhead on the entire process. FORTRAN specifies output variables that are returned immediately, so this makes for very fast interaction between the subroutine and the front end.

Is there a UNIX/Matlab user that could help me with this? I need to have a matlab command that ultimately writes results to the unix command space. Matlab has the unix command, which has a syntax of unix('command') but I need to pipe my matlab results out. The matlab command disp displays a variable. This is what I need.

So I can imagine code like this:

disp(x);>unix('|more')

But this does not work, as I can't find a way to pipe the output of disp into the unix command. Can anyone lend a hand?

Thanks

generating command line output from inside matlab

Posted: 2011/12/14 20:35:21
by pschaff
Please do not dual-post. Your duplicate post has been deleted. As you do not have a CentOS-5, or even a CentOS-specific question, your topic is being moved to Social.

You might want to try the [url=http://www.mathworks.com/matlabcentral/answers/]Matlab Community support[/url], perhaps using their search tool to look for [url=http://www.mathworks.com/matlabcentral/answers/?term=linux+pipe]linux pipe[/url] or similar.

Re: generating command line output from inside matlab

Posted: 2011/12/19 09:16:46
by DaemonProgrammr
So if I understand correctly, you want to start another script in the unix environment, from MATLAB?

if 'unix('some-command')' does the trick for executing unix commands, you might want to research adding information (or references to information) as parameters?

I'm not a MATLAB user, but in pseudo-code I'd propose the following:

command = "command-to-execute.sh "
dataset = (location-to)resultset-from-MATLAB

for element e in dataset
{
command.concatenate e.value
}

unix ('command')


This might not be very 'nice' because potentially you'd end up with a LOT of parameters, potentially breaking something in the execution.

Another way might be to have the script / program that processes the MATLAB result running as a seperate process and have the above script call a program that sends values to this script value for value. This takes some (re-)programming of the entire set of programs though..