Running a function with a parameter from the command line
32 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am new to Matlab and realize this is probably a simple question, but I am unable to find a solution online. MATLAB starts, but issues the following error:
/home/ubuntu/code/run_grisli_single.m('/home/ubuntu/my_file.tsv'); exit;
|
Invalid use of operator.
Please let me know what I am doing wrong.
This is my command:
/usr/share/matlab/bin/matlab -nodisplay -nosplash -nodesktop -r "/home/ubuntu/code/run_grisli_single.m('/home/ubuntu/my_file.tsv'); exit;"
This is my script (run_grisli_single.m):
function A = run_grisli_single(varargin)
file = varargin{1}
% compute A;
% return A;
end
2 commentaires
Harsh
le 6 Mai 2024
Try running the following command
/usr/share/matlab/bin/matlab -nodisplay -nosplash -nodesktop -r "/home/ubuntu/code/run_grisli_single('/home/ubuntu/my_file.tsv'); exit;"
Réponse acceptée
Steven Lord
le 6 Mai 2024
In general, when you are experiencing difficulties please explain what type of difficulties you're experiencing.
- Do you receive warning and/or error messages? If so the full and exact text of those messages (all the text displayed in orange and/or red in the Command Window) may be useful in determining what's going on and how to avoid the warning and/or error.
- Does it do something different than what you expected? If so, what did it do and what did you expect it to do?
- Did MATLAB crash? If so please send the crash log file (with a description of what you were running or doing in MATLAB when the crash occured) to Technical Support so we can investigate.
When you use the -r option, MATLAB runs that code as though you'd typed it in the Command Window. In the Command Window, if you wanted to run a file you wouldn't use the path to the MATLAB code file and you wouldn't use the extension.
If the MATLAB code file you're trying to run is not in a directory accessible to MATLAB (in the current directory or on the MATLAB search path) you'd need to cd to that directory or addpath the directory containing it to the search path.
3 commentaires
Steven Lord
le 7 Mai 2024
If /home/ubuntu/code/ is on the MATLAB search path, run:
/usr/share/matlab/bin/matlab -nodisplay -nosplash -nodesktop -r "run_grisli_single('/home/ubuntu/my_file.tsv'); exit;"
If it's not you'll need to run either:
/usr/share/matlab/bin/matlab -nodisplay -nosplash -nodesktop -r "cd('/home/ubuntu/code/'); run_grisli_single('/home/ubuntu/my_file.tsv'); exit;"
or
/usr/share/matlab/bin/matlab -nodisplay -nosplash -nodesktop -r "addpath('/home/ubuntu/code/'); run_grisli_single('/home/ubuntu/my_file.tsv'); exit;"
Or you could skip the need to call exit and pass in so many startup options by using the -batch option instead of -r. See the description of the two options on this documentation page for more information about what -batch does above and beyond -r.
/usr/share/matlab/bin/matlab -nodisplay -batch "run_grisli_single('/home/ubuntu/my_file.tsv');"
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!