Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

How to copy XTickLabels?

Asked by Petra on 5 Dec 2012

Dear Matlab-Users,

I try to copy an axis which is integrated in a GUI into a new figure. In this context, I face a problem with the XTickLabeling. The XTickLabels are not copied correctly. This piece of code demonstrates the problem:

data=rand(10,1);

f1=figure; ax1=axes('Parent',f1); plot(data); set(gca,'XTickLabel',[11:20])

f2=figure; copyobj(allchild(ax1),axes('Parent',f2))

f3=figure; copyobj(get(f1,'children'),f3);

ax1 is the axis I wish to duplicate. Looking at f2, it seems that allchild(ax1) does not include the XTickLabels. Figure f3 contains the correct result. But to copy all figure components is not an option for my real application, since the axis is part of a GUI. How can I copy only the axis, but get the XTickLabeling correct? Please help!

Thanks in advance

Petra

0 Comments

Petra

Products

No products are associated with this question.

1 Answer

Answer by Matt Fig on 5 Dec 2012
Edited by Matt Fig on 5 Dec 2012
Accepted answer

xticlabel is not a child of the axes, it is a property of the axes.

f1=figure; 
ax1=axes; 
plot(data); 
set(gca,'XTickLabel',[11:20])
% Now make a new figure and copy the old axes.
f2=figure; 
ax2 = copyobj(ax1,f2)

Now everything about the ax1 is copied to f2. If need be, you can always do something like:

set(ax2,'xticklab',get(ax1,'xticklab'))

0 Comments

Matt Fig

Contact us