Plot titles in for loop with string and variable names
11 次查看(过去 30 天)
显示 更早的评论
I have a for loop that gives me several plots from sec. How can i make the several plots titles display both the value of sec and a string?
if true
plot(d(:,1),d(:,2),'LineWidth',1);
leg=legend('Stock price','Location','Best');set(leg,'FontSize',8);legend('boxoff');
datetick;title(sec{1});ylabel('USD'); % code
end
0 个评论
回答(1 个)
Guillaume
2017-2-24
title(sprintf('Plot of stock %s', sec{1}));
The format specifier (%s in this case) depends on the type of variable (string, integer, real number) that you want to add to the string. Read the documentation of sprintf.
2 个评论
Guillaume
2017-2-24
As I said, look at the documentation which includes all sort of examples.
sprintf('The return for security %s is %2.4g and the standard deviation is %2.4g', sec{1}, secmean, secstd)
Coming up with a format string that does what you want is not hard.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Title 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!