graphics - Replot a deleted object MATLAB -
is possible replot line after has been deleted, using properties retrieved 'get()'.
for example:
% create plot , 'get' properties. axes p = plot(1:360, sind(1:360)); pg = get(p); % delete plot. delete(p) % replot line... plot(pg) % ?????
i'd generalizable, i.e. solution work surface plots, line plots, text annotations, etc.
approach 1: don't delete it, make invisible
instead of deleting , recreating object, make invisible:
set(p, 'visible', 'off')
and visible again
set(p, 'visible', 'on')
approach 2: create object , set property values loop
if want recreate deleted object, can proceed follows: create object of same type , use for
loop set properties stored values. try
-catch
block needed because properties read-only , issue error.
%// replot object... q = plot(nan); %// create object. plot value fields = fieldnames(pg); n = 1:numel(fields) try set(q, fields{n}, getfield(pg, fields{n})); %// set field catch end end
you can use approach other types of graphics objects, such surf
, have change line creates object (first line in code above). example, surf
like
q = surf(nan(2)); %// create object. surf needs matrix input
i have tested in r2010b plot
, surf
.
approach 3: make copy of object , restore it, using copyobj
use copyobj
make copy of object in (possibly invisible) figure, , recover that. automatically works object type.
%// create plot p = plot(1:360, sind(1:360)); = gca; %// handle axes %// make copy in figure f_save = figure('visible','off'); a_save = gca; p_saved = copyobj(p, a_save); %// delete object delete(p) %// recover copy p_recovered = copyobj(p_saved, a);
Comments
Post a Comment