How to automate the title of a graph

6 views (last 30 days)
Joshua
Joshua on 17 Jul 2013
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 Comments
Joshua
Joshua on 17 Jul 2013
I think I may have just figured it out.
title({['Length = ',num2str(length)];['Width = ',num2str(width)]})
dpb
dpb on 17 Jul 2013
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.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!