sprintf naming of figures
3 views (last 30 days)
Show older comments
Hi I'm trying to run a loop and name files based on variables. The first two variables work correctly but the rest don't show. Observer , order, and orderS are strings and Rep is an integer (1 or 2). This is an example of what it outputs as is in my folder: S10_AHAPlot_ll_ave_.fig
%plots the data
plot(phase,AHA1,phase,AHA2,phase,AHA3,phase,AHA4,phase,AHA5,phase,AHA6,phase,AHA7,phase,AHA8,phase,AHA9,phase,AHA10,phase,AHA11,phase,AHA12,phase,AHA13,phase,AHA14,phase,AHA15,phase,AHA16);
legend('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16');
grid
%saves and names the data
filename = sprintf('S10_AHAPlot_%s_%s_%s_R%u.fig', order(k), orderS(y)),Observer,Rep;
saveas(gcf,filename);
5 Comments
Stephen23
on 7 May 2020
Edited: Stephen23
on 7 May 2020
"Sure that's probably more efficient..."
It isn't just more efficient in terms of runtime, it is also more efficient in terms of your code writing and debugging time.
"I have no issues running the program other than making it name the files correctly."
Actually you do, although you might not realize it. For example, you are doing the computer's job for it.
Computers are really only good at one thing: doing simple tasks repeatedly in loops. Really everything your computer does boils down to that. So when you sit a copy-paste code or write out the names of lots of variables, you are actually just doing the menial task that your computer does better and much faster than any human can.
Having lots of numbered variables is a sign that you are doing something wrong. Using arrays is the correct solution.
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!