1

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"

1 Answer 1

3

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')"
Sign up to request clarification or add additional context in comments.

9 Comments

Thanks for the reply. I modified as you suggest. Now I get the following error: Undefined function 'calculate' for input arguments of type 'char'. ps: Typing in both ways works fine in the command line.
That's probably because calculate is not in Matlab's path. Put it in some folder Matlab sees by default (any folder included in path)
I tried this and did not work: -r "addpath('/path-to-m-file/'; calculate('input.txt','Alex','output.txt')"
It should be "addpath('/path-to-m-file/'); calculate('input.txt','Alex','output.txt')" (missing ))
Try matlab -nodisplay -nodesktop -r "addpath '/some/folder'; disp('test');" and see if that works
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.