Reputation: 3
I have two .m files. first file does the initialzation and load some data. second .m file is a function and depends on the first file.
I call matlab -nojvm -r "firstFile;secondFile(args);exit"
and it works.
but now I want to call 2nd function file several times while only call 1st file once in the beginning.
matlab -nojvm -r "firstFile;exit"
matlab -nojvm -r "secondFile(args);exit"
doesn't work.
How can I do that?
Upvotes: 0
Views: 44
Reputation: 25140
Assuming you want to stick with specifying stuff on the command line rather than writing out a separate script, you could do:
matlab -nodisplay -r "firstFile; for idx = 1:7, secondFile(args); end, exit"
Upvotes: 2
Reputation: 1274
Every time you call the matlab
command, you're starting a new instance of Matlab. Previously used variables won't be available on subsequent calls. Instead just open a command line instance on Matlab once:
matlab -nojvm -nosplash -r
firstFile
for i=1:1000
secondFile(args)
end
exit
Once you call the matlab
command, you can type any Matlab-syntax commands you want into the command line, just like you would with the Matlab GUI.
Upvotes: 1