How can I loop through different input text files when running a .exe in Matlab?

1 view (last 30 days)
Hello,
I am running a .exe file in Matlab and looping through different input arguments. This is what the code looks like:
for a = [36, 37, 38]
system(sprintf('spei.exe %d fallon_input.txt %d.txt', a, a));
end
The first argument is a time scale in months. The second argument is the input file. The input file is fallon_input.txt. And the third argument is the output file. My question is how can I loop through different input files for each set of 'a' values?

Accepted Answer

Walter Roberson
Walter Roberson on 29 Mar 2011
Just generalize what you have.
textfiles = {'fallon', 'jumpon', 'hopon'};
for a = [36,37,38]
for K = 1 : length(textfiles)
system(sprintf('spei.exe %d %s_input.txt %s_output_%d.txt', a, textfiles{K}, textfiles{K}, a));
end
end

More Answers (0)

Categories

Find more on Language Fundamentals in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!