How can I update plot title using set function?

42 views (last 30 days)
I want to update the title of plot in a loop using 'set' fucntion, but I could not find the property for "Title".
Can I update title using 'set'? Or, how can I update the title of plot?
Previously, I just re-draw plots in a loop, but the figure update gets slower.
So, I was trying to use 'set' to update the data and title only.
A brief version of my script is like below. It makes error: "Unrecognized property Title for class Line."
I tried to use 'title', but it updates title of another figure.
Thank you for reading this.
figure('Name','Window Title','NumberTitle','off');
hTracePlot = plot(1:10, zeros(1,10), '-o');
title('old title')
i = 0;
while i < 5
figure('Name','dummy window') %this figure is for another data.
set(hTracePlot,'XData',1:10,'YData',i*(1:10))
set(hTracePlot, 'Title', 'new title')
%title(['new title ' num2str(i)])
i = i+1;
keyanswer =input('enter to proceed : ','s');
end

Accepted Answer

Simon Chan
Simon Chan on 8 Aug 2021
You may modify your code based on the following if this is what you want.
i = 0;
while i < 5
subplot(2,3,i+1)
plot(1:10, i*(1:10), '-o');
t = get(gca,'Title');
set(t,'String',strcat('Figure for i = ', num2str(i)));
grid on;
i = i+1;
end

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!