How do I pass a string input argument when launching MATLAB with -r option?
11 views (last 30 days)
Show older comments
I would like to know how to pass in a string value, for example, a file name, when starting MATLAB with -r option.
Accepted Answer
MathWorks Support Team
on 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 Comments
More Answers (0)
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!