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 Center および File ExchangeTitle についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by