2

I've a MATLAB function that perform some operations with variables previously loaded in the workspace. In example:

do_something(A, B, C, ...);

I run the function n times in MATLAB with different subsets of A, B, C .... The output is save as ASCII for further processing with a C++ program.

I would like to time the whole process. So I thought to run the MATLAB function from the shell script, followed by the C++ programs. In example:

matlab -nojvm -nodesktop -nosplash -r "run matlabTest"; ./c++Test;

But I realized that the MATLAB function need some variables which are not previously loaded. So, my question is How to run a the MATLAB function with parameters which are in a workspace? . The workspace is saved in the same directory.

I'm working on Linux with MATLAB 7.9.0 (R2009b).

I've noticed (while reading/reviewing this question) that I can run linux commands in MATLAB using the system function. I've successfully done this but I would not stay with the doubt of how to do the other way.

2 Answers 2

4

You can include multiple MATLAB commands within the quotes, separated by ;. You could try

matlab -nojvm -nodesktop -nosplash -r "mydata = 1; run matlabTest"; ./c++Test;

for example. If you need many variables and this becomes lengthy or inconvenient, perhaps you could save the workspace variables off to a .mat file (say mydata.mat), and then load them in:

matlab -nojvm -nodesktop -nosplash -r "load mydata; run matlabTest"; ./c++Test;

PS You don't need run, just call matlabTest directly.

0

For running matlab script (with parameters) in background on Ubuntu using nohup, the following command works for me:

nohup matlab -nodisplay -nosplash -nojvm -nodesktop -r "demCF datasetName 1 10 1000 0" 2>&1 > demCF_datasetName_100.out &

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.