i iteratively create subplots figure. have following code:
for i=1:numel(snips_timesteps) x=openfig(sprintf('./results/snips/temp/%d.fig',i),'reuse'); title(sprintf('timestep %d',snips_timesteps(i))); xlabel(''); ax= gca; handles{i} = get(ax,'children'); close gcf; end h3 = figure; %create new figure i=1:numel(snips_timesteps) s=subplot(4,4,i) copyobj(handles{i},s); end
error is:
error using copyobj copyobj cannot create copy of invalid handle. k>> handles{i} ans = 3x1 graphics array: graphics (deleted handle) graphics (deleted handle) graphics (deleted handle)
is possible close figure still retain it's handle? seems reference being deleted.
edit
handles={}; i=1:numel(snips_timesteps) x=openfig(sprintf('./results/snips/temp/%d.fig',i),'reuse'); title(sprintf('timestep %d',snips_timesteps(i))); xlabel(''); ax= gca; handles{i} = get(ax,'children'); %close gcf; end h3 = figure; %create new figure i=1:numel(snips_timesteps) figure(h3); s=subplot(4,4,i) copyobj(handles{i},s); close(handles{i}); end
error:
k>> handles{i} ans = 3x1 graphics array: line quiver line k>> close(handles{i}) error using close (line 116) invalid figure handle.
if remove close(handles{i})
plots first figure again subplots!
no. closing figure deleting , of data associated including handle.
if remove close gcf;
, place figure(i); close gcf;
after copyobj(handles{i},s);
desired affect. however, need add figure(h3);
before s=subplot(4,4,i)
ensure subplot added correct figure.
here sample code show working. first creates 4 figures , grabs handles axes it. loop on each figure , copy subplot of figure.
for = 1:4 figure(i) y = randi(10, [4 3]); bar(y) ax = gca; handles{i} = get(ax, 'children'); end = 1:4 figure(5); s = subplot(2, 2, i); copyobj(handles{i}, s); figure(i); close gcf; end
Comments
Post a Comment