How to automate the title of a graph

4 次查看(过去 30 天)
Joshua
Joshua 2013-7-17
I need to output several graphs with titles automatically. I want the titles to reflect a series of input data, but I do not know how to do this. Any ideas?
Here is an example of what I mean
c = input('select 1 or 2');
if c==1
length = 5;
width =2;
end
if c==2
length = 1;
width = 0.5;
end
If I select 1, I want my title on the figure to look like the following
Length = 5
Width = 2
There's got to be a way to code it so this gets done automatically, but I can't figure it out.
  2 个评论
Joshua
Joshua 2013-7-17
I think I may have just figured it out.
title({['Length = ',num2str(length)];['Width = ',num2str(width)]})
dpb
dpb 2013-7-17
Alternatively,
title(sprintf('Length = %d\nWidth = %d',[leng width]))
NB: STRONGLY suggest to not overload the builtin function LENGTH w/ the variable of the same name--this will only cause grief to do so later on when try to use the function to, say, control a for loop upper limit.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Title 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by