Already Saved Subplots to subplots including title and labels
3 ビュー (過去 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!