sprintf naming of figures
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
Stephen23
2020-5-7
编辑:Stephen23
2020-5-7
"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.
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!