Append/Alter string in Title

8 views (last 30 days)
John Petersen
John Petersen on 2 May 2012
I would like to append additional text to the title of a plot. How do I "get" the title string in order to append the added text and replace the title with the modified string?
The help tells me how to replace the title, but I want to add, say, a date, or filename.

Accepted Answer

Wayne King
Wayne King on 2 May 2012
plot(randn(100,1));
h = title('Test');
origtitle = get(h,'String');
set(h,'String',[origtitle ' 2'])
  3 Comments
Daniel Shub
Daniel Shub on 3 May 2012
The terminology matters here: Figure->Axis->Object. The gca function returns the handle to the current Axis, not the Figure. The plot handle (presumably the handle returned by plot), is a handle to an Object.
The axis object has a child object called Title. You can get this with h = get(gca, 'Title'). The h from this command will be identical to the h in Wayne's answer.
John Petersen
John Petersen on 3 May 2012
That clears up my followup question. Thankyou!

Sign in to comment.

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!