问题
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