user3131944
user3131944

Reputation: 21

Running Matlab .m file with arguments in a bash script

I have a Matlab .m file that takes three input arguments:

calculate('input.txt','Alex','output.txt')

I would like to run this .m file in a shell script as follows:

matlab -nodisplay -nodesktop -r "run calculate('input.txt','Alex','output.txt)"

Unfortunately, this did not work. I get the following error:

Error using run (line 70)

calculate('input.txt','Alex','output.txt') not found.

Any pointer as to how I can give the input arguments/variables?

Thanks.

Note: The following did not work either - complaining too many arguments.

matlab -nodisplay -nodesktop -r "run calculate input.txt Alex output.txt"

Upvotes: 1

Views: 2706

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112679

I think you just need to remove run. run is for scripts, not for functions (and anyway it's not necessary unless you need to specify the script's path). So, try

matlab -nodisplay -nodesktop -r "calculate('input.txt','Alex','output.txt')"

If your function calculate is not in Matlab's path, change to its folder first. For example

matlab -nodisplay -nodesktop -r "cd 'c:\users\Alex\SomeFolder'; calculate('input.txt','Alex','output.txt')"

Upvotes: 3

Related Questions