Unix commandline start: passing arguments to m file
1 view (last 30 days)
Show older comments
I want to achieve.
- Start matlab in unix using commandline
- pass myfunc.m file
- myfunc.m asks for input from user. square x if input is <1>, cube x if input is <2> or print x if input is <3>
- myfunc.m asks for second input from user: print result as integer if input <1> or print as whole number if input is <2>
- lastly, myfunc.m asks for 3rd input from user: plot if input is <plot> or exit without plot if input is <noplot>
step 1 and 2 are executing by running below commandline. How do I achieve steps 3 to 5 ?
matlab -nosplash -nodisplay -nojvm -nodesktop < myfunc.m
I don't want to modify myfunc.m as it is provided by another user and it typically keeps changing.
0 Comments
Answers (1)
Walter Roberson
on 30 Jul 2015
matlab -nosplash -nodisplay -nojvm -nodesktop -r "try; myfunc; catch ME;end;quit"
7 Comments
Walter Roberson
on 1 Aug 2015
On my system, printf does work:
printf "1\n1\nplot\n" | matlab -nosplash -nodisplay -nojvm -nodesktop -r "input('A'),input('B'),input('C','s')"
The character that needs to be sent is newline (control-J, char(10)). echo cannot always send that in one go. printf can. Multiple echo grouped together in a pipe will emit a newline between each, (echo 1;echo 1; echo plot) | .....
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!