필터 지우기
필터 지우기

Merge two .fig figures side by side by connecting yaxes in matlab

조회 수: 9 (최근 30일)
Apashanka Das
Apashanka Das 2022년 2월 28일
댓글: Apashanka Das 2022년 3월 4일

I have two figure files 'A.fig' and 'B.fig'. I want to have the two figues side by side such that right hand vertical axes line of 'A.fig' get merged with the left hand vertical axes line (yaxes) of 'B.fig'. And the new merged figure say 'C.fig' should be in .pdf format. Can anybody please help me out ? It would be of great help. I am posting the pdf files of 'A.fig' and 'B.fig'.

  댓글 수: 2
Matt J
Matt J 2022년 2월 28일
It would be easier for us if you post the original .fig files.
Apashanka Das
Apashanka Das 2022년 3월 2일
@Matt J Sorry sir for late reply. I am posting here the original .fig files 'A.fig' and 'B.fig'. Please help me out. It would be of great help. Thanks.

댓글을 달려면 로그인하십시오.

채택된 답변

Robert U
Robert U 2022년 3월 2일
Hi Apashanka Das,
you can copy objects from figure to figure using copyobj(). A bit tricky is to write a generally working code that can deal with different types of figures. But the function sketched below should be able to deal with the figures you have although it might need some adjustment to coloring.
open A.fig
open B.fig
mergeOpenFigs('C',1)
function [ newFh ] = mergeOpenFigs( sSaveFilename,saveFlag )
oldFh = findall(groot,'Type','figure');
% restore correct order of graphs
[~,indFh] = sort([oldFh.Number],'ascend');
oldFh = oldFh(indFh);
oldLegends = findall(oldFh,'Tag', 'legend');
oldAh = findall(oldFh,'Type','Axes');
newFh = figure;
oldFigPosition = vertcat(oldFh.Position);
newFh.Position = [newFh.Position(1:2), max(oldFigPosition(:,3:4),[],1)];
newAh = axes(newFh);
hold(newAh,'on');
colorOrder = get(0,'DefaultAxesColorOrder');
for ik = 1:size(oldAh)
copyobj(oldAh(ik).Children,newAh)
newAh.Children(ik).Color = colorOrder(ik,:);
labelString(ik,:) = {oldAh(ik).XLabel.String oldAh(ik).YLabel.String};
end
newAh.XLim = max(vertcat(oldAh.XLim),[],1);
newAh.YLim = max(vertcat(oldAh.YLim),[],1);
newAh.XLabel.String = unique(labelString(:,1));
newAh.YLabel.String = unique(labelString(:,2));
legend(newAh);
close(oldFh);
if saveFlag
if exist('sSaveFilename','var')
saveas(newFh,sSaveFilename,'fig');
saveas(newFh,sSaveFilename,'pdf');
close(newFh);
newFh = [];
end
end
end
Kind regards,
Robert

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by