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

77 views (last 30 days)
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.

Accepted Answer

Image Analyst
Image Analyst on 28 Sep 2014
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);
% Now change it.
caption1 = sprintf('This is %d', 99);
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.
Image Analyst
Image Analyst on 29 Sep 2014
Sure, just do this:
caption1 = 'As you knows: this is the same.';
% Now change it.
caption2 = As you knows: this must change as you need.
or, if you have the first part as a string:
str = caption1 = 'As you knows: ';
caption1 = sprintf('%s this is the same.', str);
% Now change it.
caption2 = sprintf('%s this must change as you need.', str);

Sign in to comment.

More Answers (1)

Antonio Trujillo-Ortiz
Antonio Trujillo-Ortiz on 28 Sep 2014
Thanks to Image Analyst and Mohammad. Both answers are useful.
Stephen23 on 29 Sep 2014
Ouch. Better to write a comment as a reply, unless you are actually answering your own question.

Sign in to comment.


Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!