Already Saved Subplots to subplots including title and labels
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Benjamin Kraus
2017-11-9
编辑:Benjamin Kraus
2017-11-9
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 个评论
Olumide Omotere
2020-1-31
I got the error there no current axes property on the figure class. I do i resolve this.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!