Filter löschen
Filter löschen

Run MATLAB script and pass variables in Linux terminal

37 Ansichten (letzte 30 Tage)
Chaabane
Chaabane am 2 Dez. 2019
Kommentiert: Chaabane am 17 Feb. 2020
Hello,
I'm trying to run a script file "test.m" from Linux terminal that does the following :
AllFiles = dir(FilePath)
I want to declare FilePath in matlab workspace before calling the script.
I'm using the following line of code but Matlab reporting error : undefined FilePath!
matlab -nodisplay -nosplash -nodesktop -r "FilePath='data';test; exit;"
I also tried using function to pass variable as argument but my paths have spaces and I can't change that, this results for some confusing between linux and matlab path rules !
My function is
function testfcn(FilePath)
FilePath
AllFiles = dir(FilePath)
end
matlab -nodisplay -nosplash -nodesktop -r "testfcn('slprj/New Folder/');exit;"
When I have no space in my path things works but not when path contain space. I tried adding \ before the space caractere, enclose the whole path by ".
Any idea on how to overcome this issue ?

Akzeptierte Antwort

Bhargavi Maganuru
Bhargavi Maganuru am 17 Feb. 2020
You can make use of -r option in the matlab command
For example if your function is
function test(FilePath)
AllFiles = dir(FilePath);
end
You can call the function using following command
matlab -nodisplay -nosplash -nodesktop -r "test(data)" % where data is the name of the folder
This command also works when there is space in the name of the folder.
  1 Kommentar
Chaabane
Chaabane am 17 Feb. 2020
Thank you, indeed I already implemented it. somehow I miss wrote the command.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by