Unix commandline start: passing arguments to m file

1 view (last 30 days)
I want to achieve.
  1. Start matlab in unix using commandline
  2. pass myfunc.m file
  3. 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>
  4. myfunc.m asks for second input from user: print result as integer if input <1> or print as whole number if input is <2>
  5. 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.

Answers (1)

Walter Roberson
Walter Roberson on 30 Jul 2015
matlab -nosplash -nodisplay -nojvm -nodesktop -r "try; myfunc; catch ME;end;quit"
  7 Comments
Mustafa Khan Patan
Mustafa Khan Patan on 31 Jul 2015
Thank you.
I still am look for how to pass enterkey / carriage return from echo (unix) to matlab process ID.
Or how do you pass enter key in a matlab command window without actually pressing enter key on keyboard ?
Walter Roberson
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) | .....

Sign in to comment.

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!