matlab rename plot title automatically with loop

强颜欢笑 提交于 2019-12-12 06:57:37

问题


I have trouble renaming my plots in a loop. I tried

for Yearnumber 2000:2018
 etc etc
title('Plot for year %g',Yearnumber,'FontSize',20);

end

similar to what I type into sprintf but it doesnt work. Is there any way to make it loop through the years?


回答1:


You can just use sprintf within the title()

for Yearnumber = 2000:2018
    title( sprintf( 'Plot for year %g', Yearnumber ), 'FontSize', 20);
end



回答2:


spirntf is a good answer, and you can also do this:

for Yearnumber = 2000:2018
    title( ['Plot for year' num2str(Yearnumber)], 'FontSize', 20);
end


来源:https://stackoverflow.com/questions/52181772/matlab-rename-plot-title-automatically-with-loop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!