Error running matlab from linux command line

15 次查看(过去 30 天)
I am running matlab on a remote server. Its far away and I do not want to run XORG. I run my start up no issues:
matlab -nosplash -nodisplay -nodesktop < linux_startup_robot.m
But when I run my main file to begin recording data like this:
matlab -nosplash -nodisplay -nodesktop < main.m
I get this error:
>> function main()
|
Error: Function definitions are not permitted in this context.
I know that this code works, when I run on a local machine its not an issue and everything runs as expected.
Please help.

采纳的回答

Ashley
Ashley 2015-7-20
Thanks for getting back to me.
So this didn't work for me because it kind of opens matlab from the terminal. Then I struggle to get out and run the rest of my scripts that need the initialization script before that.
How I solved it was buy writing a m file that just called main so:
main_called.m literally just has:
main

更多回答(1 个)

Steven Lord
Steven Lord 2015-7-17
Don't pipe your function into MATLAB. Use the -r startup option instead.
matlab -nosplash -nodisplay -nodesktop -r why
If you want to execute multiple commands, wrap them in quotes.
matlab -nosplash -nodisplay -nodesktop -r "for k = 1:10, why, end"
matlab -nosplash -nodisplay -nodesktop -r "why, quit"
matlab -nosplash -nodisplay -nodesktop -r "rng('shuffle'), why, quit"
The reason piping worked for your first example is because your linux_startup_robot.m is a script file, not a function file. But -r will work to run scripts or functions, instantiate classes, or execute arbitrary code as above.

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by