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