How do I create a string for a plot title from one fixed string and one I get from INPUT?

조회 수: 2 (최근 30일)
I have a problem in plot's titles. I do the following:
name = input('plot''s title');
set(gcf,'NumberTitle','off');
set(gcf,'Name',name);
This is perfectly OK and it gives the name that is already input as a title, but I want to have a title in which one part is always fix and the other part is the name that I can change it each time. For example I would like to have titles like this:
name1_name2
name1_name3
name1_name4

채택된 답변

Arnaud Miege
Arnaud Miege 2011년 5월 27일
name1 = input('Plot's title part 1','s');
name2 = input('Plot's title part 2','s');
t = 0:0.01:10;
y = sin(t);
plot(t,y)
title([name1 '_' name2],'Interpreter', 'none')
set(gcf,'Name',[name1 '_' name2]);
HTH,
Arnaud
  댓글 수: 2
M G
M G 2011년 5월 27일
Thanks a lot Arnaud; this is what I want. One thins that I didn't understand is the 6th line (title([name1 '_' name2],'Interpreter', 'none')). What does it do? Cause even if it is removed the program still works appropriately!
Arnaud Miege
Arnaud Miege 2011년 5월 27일
set(gca,'Name',...) sets the name of the figure window, not the title of the plot. title(...) puts a title on the actual plot. The 'Interpreter' property is for the TeX intepreter so that it doesn't think the '_' means a subscript. Have a look at the doc for title:
http://www.mathworks.com/help/releases/R2011a/techdoc/ref/title.html

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ben Mitch
Ben Mitch 2011년 5월 27일
In addition to what Arnaud suggests, I also sometimes find it useful to keep a bit of name in the plot and change only the second bit when you update it. For example, use
set(gcf, 'Name', ['My Application: My Document']);
to set the title initially, then update the 'document name' (or whatever) using something like this:
name = get(gcf, 'Name');
set(gcf, 'Name', [name(1:find(name == ':')+1) 'My New Document']);

카테고리

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