Get title of current figure in MATLAB?
I have a figure opened with a certain title. How do I get the title string?
I have tried get(gcf) but I don't know how to navigate to the title.
I want to get the title of many figures, add some more characters to the string and write it back.
x=0:.1:3.14; plot(sin(x)) title('Sin(x)') %get the title h=get(gca,'Title'); t=get(h,'String') %t is now 'Sin(x)' %new title new_t=strcat(t,' Sine function') title(new_t)
Given a handle to a figure window, this shows how you can "get" and "set" the "title" of the figure.
Run the following lines of code and see for yourself. I used Matlab 2016a.
Here is a summary:
h = figure; h.Children.Title.String = 'Your desired title'; disp(['Current Figure Title: ', h.Children.Title.String]); figure(h);
Create a demo figure with title: 'Test Title-1'
h = figure; title('Test Title-1');
Access the figure title through the handle: h
figTitle = h.Children.Title.String; disp(['Current Figure Title: ',figTitle]); figure(h);
Change the figure title to something new: 'Test Title-2'
h.Children.Title.String = 'Test Title-2'; disp(['New Figure Title:',h.Children.Title.String]); figure(h);