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!