Already Saved Subplots to subplots including title and labels

4 Ansichten (letzte 30 Tage)
Pankaj
Pankaj am 9 Nov. 2017
Kommentiert: Olumide Omotere am 31 Jan. 2020
I am trying to reproduce already saved figures (.fig) to subplots in new figure I have tried the following code which I have found here . The code is works fine but it does not copy titles and labels, can someone suggest how it could be done
% Load saved figures
c=hgload('MyFirstFigure.fig');
k=hgload('MySecondFigure.fig');
% Prepare subplots
figure
h(1)=subplot(1,2,1);
h(2)=subplot(1,2,2);
% Paste figures on the subplots
copyobj(allchild(get(c,'CurrentAxes')),h(1));
copyobj(allchild(get(k,'CurrentAxes')),h(2));
% Add legends
l(1)=legend(h(1),'LegendForFirstFigure')
l(2)=legend(h(2),'LegendForSecondFigure')
Robenson's suggestion to try the following produces the error
co
copyobj(allchild(c), h(1))
copyobj(allchild(k), h(2))
Error:
Warning: This Menu cannot be copied. See what you can and cannot copy with COPYOBJ.

Antworten (1)

Benjamin Kraus
Benjamin Kraus am 9 Nov. 2017
Bearbeitet: Benjamin Kraus am 9 Nov. 2017
Your first approach is copying all the axes children from one axes to another, which is not copying the axes itself (just its children), so it is not getting the title and labels (because those are properties on the axes).
Your second approach is trying to copy all the figure's children, which includes the toolbar and figure menus, so that is going a little overboard.
You could try copyobj on just the figure's children into a new figure.
f = figure;
ax1 = copyobj(c.Children, f);
ax2 = copyobj(k.Children, f);
Now you will likely need to set the position on the children in the new figure, so they don't overlap. Assuming each starting figure has a single axes, you can also add existing axes to a subplot like this:
subplot(1, 2, 1, ax1)
subplot(1, 2, 2, ax2)
If that doesn't work, we would need more details about your starting figures. Do they have legends or colorbars? How many axes are in each figure?
  1 Kommentar
Olumide Omotere
Olumide Omotere am 31 Jan. 2020
I got the error there no current axes property on the figure class. I do i resolve this.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by