What is the closest way to pass string arguments from a bash script to a matlab file?

I have a matlab file matlab_param.m

function matlab_param(param1, param2) disp(sprintf('param1 : %s', param1)); disp(sprintf('param2 : %s', param2)); 

And I want to have a bash script bash_param.sh that look like

 #!/bin/bash echo $1 echo $2 ./matlab_param.m $1 $2 

I want to run this bashscirpt

 ./bash_param.sh hello world 

and he will print

 hello world param1 : hello param2 : world 

I google for several hours and did not find an exact solution for this. The closest I got so far

 matlab -nodesktop -nosplash -nodisplay -r "try, run ('./test_param.m'); end; quit" 

which I need for hard coding of all parameters.

+6
source share
2 answers

Have you tried:

 #!/bin/bash echo $1 echo $2 matlab -nodesktop -nosplash -nodisplay -r "try, test_param('$1','$2'); end; quit" 
+5
source

If you want to pass arguments to the matlab function, I would recommend creating a simple shell script:

 matlab -nodisplay -r "try, test_param('$1','$2'); end; exit" 

Then you can run on unix:

 $ sh test_param.sh hello world 

Not sure though how to avoid the MATLAB header output and if it will be passed to the channel.

+2
source

Source: https://habr.com/ru/post/912497/


All Articles