run function from command line
56 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Simon Michel
le 27 Fév 2017
Modifié(e) : Walter Roberson
le 12 Sep 2025 à 1:56
I want to start a matlab function from the unix command line. For now I use
matlab -nodisplay -r "functionname(argument1, argument2, argumentN);exit"
But for this the function I call needs to be in the folder where I am. Is there a way to call the function like
matlab -nodisplay -r "/path/to/functionname(argument1, argument2, argumentN);exit"
without manually adding it to the search path of matlab?
0 commentaires
Réponse acceptée
Jan
le 27 Fév 2017
Do you mean:
matlab -nodisplay -r "cd('/path/to'); functionname(argument1, argument2, argumentN);exit"
4 commentaires
Jhe Mag
le 16 Jan 2022
Modifié(e) : Jhe Mag
le 16 Jan 2022
Thank you Mr. Jan. Seems like windows prompt is slightly the same with unix haha.
Someone might be needing this: For windows command prompt, I used the command : "C:\Program Files\Polyspace\R2021a\bin\matlab.exe" -nosplash -nodesktop -r "cd('D:\matlab_project\scripts\'), testFnc('blah'), exit"
with my testFnc.m
function sample = testFnc(stri)
sample = stri
disp(sample)
end
Jon
le 11 Sep 2025 à 20:16
FWIW, this does seem to cd back to the original directory after MATLAB exits
Plus de réponses (1)
Steven Lord
le 12 Sep 2025 à 1:46
I'm not 100% sure this option was available in releases R2017a or R2017b, but I'm pretty sure it was. Use the -sd startup option to cause MATLAB to start in a certain directory.
0 commentaires
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!