Basically I have an m file which looks like
function Z=myfunc()
% Do some calculations
dlmwrite(\'result.out\',Z,\',\');
end
Here's a simple solution that I found.
I have a function func(var) that I wanted to run from a shell script and pass it the first argument for var. I put this in my shell script:
matlab -nodesktop -nosplash -r "func('$1')"
That worked like a treat for me. The trick is that you have to use double quotes with the "-r" command for MATLAB and use single quotes in order to pass the bash argument to MATLAB.
Just make sure that the last line of your MATLAB script is "exit" or that you run
matlab -nodesktop -nosplash -r "func('$1'); exit"