I would like to iteratively create subplots from a figure. I have the 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
for i=1:numel(snips_timesteps)
s=subplot(4,4,i)
copyobj(handles{i},s);
end
Error I get is:
Error using copyobj
Copyobj cannot create a copy of an
invalid handle.
K>> handles{i}
ans =
3x1 graphics array:
Graphics (deleted handle)
Graphics (deleted handle)
Graphics (deleted handle)
Is it possible to close a figure but still retain it's handle? It seems like the reference is being deleted.
Edit
handles={};
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
for 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 I remove close(handles{i}) it plots the first figure again for all subplots!