我正在使用以下代码将保存的绘图复制到另一个。
fig1 = openfig('ABC.fig');
fig2 = openfig('DEF.fig', 'invisible');
copyobj(fig2.Children.Children, fig1.Children);
这工作得很好,只要我在fig2
中不使用图例,那么我得到一个错误消息,因为在copyobj
中使用太多的输入参数。在文档中,我了解到,copyobj
不复制传奇的上下文菜单,所以我要求你的帮助,以及复制传奇。
如下所示:
plot(rand(2))
l = legend('show'); % legend
ax = gca; % associated axes
fnew = figure;
copyobj([l,ax],fnew)
% This is what the error was telling you.
% You need to pass your axes object
% along with you legend object as an array of graphic objects
(l, ax)
ans =
1×2 graphics array:
Graphics Graphics