How do I copy a figure object and its descendants to another object of the same class in MATLAB?
4 次查看(过去 30 天)
显示 更早的评论
I have a figure with several objects such as curves, annotations etc. I want to be able to copy all the objects in the figure to another figure while retaining the same hierarchy.
采纳的回答
MathWorks Support Team
2010-9-8
The function COMPCOPY below is an example of how to implement such a functionality.
function compCopy(op, np)
%COMPCOPY copies a figure object represented by "op" and its % descendants to another figure "np" preserving the same hierarchy.
ch = get(op, 'children');
if ~isempty(ch)
nh = copyobj(ch,np);
for k = 1:length(ch)
compCopy(ch(k),nh(k));
end
end;
return;
The function can be used as follows
hf1 = figure;
ax1 = subplot(211);
plot(1:10);
title('First Figure');
ax2 = subplot(212);
plot(31:40);
title('Second Figure');
hf2 = figure;
compcopy(hf1, hf2);
For information on the COPYOBJ function execute the following at the MATLAB command prompt:
doc copyobj
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Identification 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!