Basically I have an m
file which looks like
function Z=myfunc()
% Do some calculations
dlmwrite(\'result.out\',Z,\',\');
end
You can run an arbitrary function from the commandline by passing a command to Matlab, like this:
matlab -nodisplay -r "funcname arg1 arg2 arg3 argN"
This will execute the Matlab command funcname('arg1', 'arg2', 'arg3', 'argN')
. Ergo, all arguments will be passed as strings and your function needs to handle this, but then again, this applies to command-line options in any other language as well.
You could compile myfile
into a standalone program and run that instead. Use Matlab's compiler mcc
for that (if you have it), more information is provided in this question.
This answer was copied from my answer to another question.