Clear Filters
Clear Filters

How to apply an existing text object to a new figure

4 views (last 30 days)
In my script I have created text objects for a figure's title, y label and x label and then modified these objects' properties as desired as seen here:
figure(1)
plot((1:length(theta))/dataframe(n).videoObject.FrameRate,theta,'Color',bankColour,'Marker','.','LineStyle','none')
xlab1=xlabel('Time (seconds)');
ylab1=ylabel('Bank angle (degrees)');
tit1=title(['Bank angle - ',dataframe(n).birdID],'Interpreter','none');
xlab1.FontSize=14;
xlab1.FontWeight='bold';
xlab1.FontName='calibri';
ylab1.FontSize=14;
ylab1.FontWeight='bold';
ylab1.FontName='calibri';
tit1.FontSize=14;
tit1.FontName='calibri';
tit1.FontWeight='bold';
Later in the script I want to make another figure using exactly the same labels and associated properties (i.e. FontSize, FontWeight and FontName).
As these labels exist as text objects in the form of xlab1, ylab1 and tit1, is there a way of calling these objects to my new figure without having to create new objects and rewriting the above code again for the new figure?

Accepted Answer

Walter Roberson
Walter Roberson on 9 Jun 2020
Edited: Walter Roberson on 9 Jun 2020
newfig = figure();
newax = axes(newfig);
xlab2 = copyobj(xlab1, newax);
newax.XRuler.Label = xlab2;
ylab2 = copyobj(ylab1, newax);
newax.YRuler.Label = ylab2;
tit2 = copyobj(tit1, newax);
newax.Title = tit2;
Note: the copyobj() is important: without it, the text items would disappear from the original location.

More Answers (0)

Tags

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!