How change part of a text in fprintf, title and subtitle?

조회 수: 61 (최근 30일)
Antonio Trujillo-Ortiz
Antonio Trujillo-Ortiz 2014년 9월 28일
댓글: Stephen23 2014년 9월 29일
Hi all,
I need your help. How one can change as needed part of a text in the fprintf, title and subtitle, and leaving the another one fixed.
I would apprteciate any hint on this. Thx.
Antonio

채택된 답변

Image Analyst
Image Analyst 2014년 9월 28일
Just blast over it with the new string. I mean, you put the string in there so somehow you know what you put it. So you could just make up a new string
caption1 = sprintf('This is %d', 10);
title(caption1);
% Now change it.
caption1 = sprintf('This is %d', 99);
title(caption1);
If, for some reason you don't know what's there, then you can retrieve it
existingCaption = get(gca, 'title'); % Or something like that
Then use strfind() or indexing to parse and change the string elements you want changed.
  댓글 수: 2
Image Analyst
Image Analyst 2014년 9월 29일
Antonio's response to me from moved from an "Answer" to a Comment to me:
Hi Image Analyst,
Thanks for your soon answer. What with a title or subtitle? How you can keep fixed part of a text but the another one changing as you need?
Eg.
Suppose in a case you need a title as:
As you knows: this is the same.
and in another case,
As you knows: this must change as you need.
First part is fixed, the another is different
Antonio
Image Analyst
Image Analyst 2014년 9월 29일
Sure, just do this:
caption1 = 'As you knows: this is the same.';
title(caption1);
% Now change it.
caption2 = As you knows: this must change as you need.
title(caption2);
or, if you have the first part as a string:
str = caption1 = 'As you knows: ';
caption1 = sprintf('%s this is the same.', str);
title(caption1);
% Now change it.
caption2 = sprintf('%s this must change as you need.', str);
title(caption2);

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

추가 답변 (1개)

Antonio Trujillo-Ortiz
Antonio Trujillo-Ortiz 2014년 9월 28일
Thanks to Image Analyst and Mohammad. Both answers are useful.
Antonio
  댓글 수: 3
Antonio Trujillo-Ortiz
Antonio Trujillo-Ortiz 2014년 9월 28일
Dear Image Analyst,
As I already did. I'm sorry. By a type error I accepted my answer myself . It must have been that of Mohammad.
Antonio
Stephen23
Stephen23 2014년 9월 29일
Ouch. Better to write a comment as a reply, unless you are actually answering your own question.

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by