Question

I have two figures with figure handles h1 and h2. I'd like to use them as subplots in a single figure and run

figure
s1=subplot(211);
s2=subplot(212);
hc1=get(h1, 'children');
hcc1=get(hc1, 'children');
hc2=get(h2, 'children');
hcc2=get(hc2, 'children');
set(hcc1,'parent',s1);
set(hcc2,'parent',s2);

This works well for the first figure but not the second (h2), where I get the error

Error using set
Conversion to double from cell is not possible.

The two figures are the same except for details, so I don't understand why. I tried using set(hc2,'parent',s2);, i.e. "one less parent," and also one more, i.e. hccc2=get(hcc2, 'children'); set(hcc2,'parent',s2);, with the same errors. Can anyone see what's going on?

Was it helpful?

Solution

To get a specific type of object's handle, try using findobj to look for a specific 'Type' property. For example,

ha1 = findobj(h1,'Type','axes');

However, you can probably just apply copyobj (instead of changing the 'parent':

copyobj(ha1,hf2)

This way you can copy the axes (ha1) to a new figure (hf2). You can do the same with any graphics element, like copying a plot ('Type' of 'line') to a new axes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top