How do I pass a string input argument when launching MATLAB with -r option?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I would like to know how to pass in a string value, for example, a file name, when starting MATLAB with -r option.
Akzeptierte Antwort
MathWorks Support Team
am 27 Jun. 2009
Suppose you have a MATLAB function that opens a file and reads its contents using TEXTSCAN:
function myValues = readMyFile(filename)
fid = fopen(filename, 'r');
myValues = textscan(fid, '%s');
end
Use either of the following commands to pass in your filename (assuming both the file and your MATLAB function are in current DOS working directory) when starting MATLAB:
matlab -r readMyFile('myFile.txt')
or
matlab -r "readMyFile('myFile.txt')"
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu File Operations finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!