Edd*_*heB 3 graphics matlab matlab-figure
是否可以使用先前由'get()'检索的属性在删除后重新绘制一行.
例如:
% Create the plot and 'get' its properties.
axes
P = plot(1:360, sind(1:360));
PG = get(P);
% Delete the plot.
delete(P)
% Replot the line...
plot(PG) % ?????
Run Code Online (Sandbox Code Playgroud)
我希望它是可推广的,即解决方案适用于表面图,线图,文本注释等.
您可以使其不可见,而不是删除和重新创建对象:
set(P, 'visible', 'off')
Run Code Online (Sandbox Code Playgroud)
然后再次可见
set(P, 'visible', 'on')
Run Code Online (Sandbox Code Playgroud)
如果您确实要重新创建已删除的对象,可以按以下步骤操作:创建相同类型的对象并使用for循环将其属性设置为存储的值.需要A try-catch块,因为某些属性是只读的并发出错误.
%// Replot the object...
Q = plot(NaN); %// create object. Plot any value
fields = fieldnames(PG);
for n = 1:numel(fields)
try
set(Q, fields{n}, getfield(PG, fields{n})); %// set field
catch
end
end
Run Code Online (Sandbox Code Playgroud)
您可以将此方法与其他类型的图形对象一起使用,例如surf,但是您必须更改创建对象的行(上面代码中的第一行).例如,surf它就像是
Q = surf(NaN(2)); %// create object. surf needs matrix input
Run Code Online (Sandbox Code Playgroud)
我已经在R2010b中用plot和测试了这个surf.
copyobj用于copyobj在另一个(可能是不可见的)图形中制作对象的副本,然后从中恢复它.这自动适用于任何对象类型.
%// Create the plot
P = plot(1:360, sind(1:360));
a = gca; %// get handle to axes
%// Make a copy in another figure
f_save = figure('visible','off');
a_save = gca;
P_saved = copyobj(P, a_save);
%// Delete the object
delete(P)
%// Recover it from the copy
P_recovered = copyobj(P_saved, a);
Run Code Online (Sandbox Code Playgroud)