Load figures from .fig files and copy into subplots including legends and axis labels

26 ビュー (過去 30 日間)
Robin Hellmers
Robin Hellmers 2019 年 11 月 3 日
コメント済み: Walter Roberson 2019 年 11 月 6 日
I have searched for several questions which partly does this, but I don't manage to do it all.
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 11 月 6 日
Note: it is not completely possible to copy figures into subplots. figure objects can have interactive behaviour that cannot be associated with uipanels or axes.

サインインしてコメントする。

回答 (1 件)

Subhadeep Koley
Subhadeep Koley 2019 年 11 月 6 日
Robin, refer to the below demo code which loads 2 figures from .fig files and plot them into a new subplot along with legends and axis labels.
close all;
% Create and save demo figures
fig1 = figure; plot(rand(1,50)); axis tight; legend('Data 1');
savefig(fig1,'fig1.fig');
fig2 = figure; plot(rand(1,100)); axis tight; legend('Data 2');
savefig(fig2,'fig2.fig');
% Close the figures
close all;
% Open fig1 and extract X, Y, legend values from it
fig = openfig('fig1.fig','invisible');
dataObjs = findobj(fig,'-property','YData');
y1 = dataObjs(1).YData;
dataObjs = findobj(fig,'-property','XData');
x1 = dataObjs(1).XData;
leg1 = findobj(fig,'type','legend');
legText1 = leg1.String{1};
% Open fig2 and extract X, Y, legend values from it
fig = openfig('fig2.fig','invisible');
dataObjs = findobj(fig,'-property','YData');
y2 = dataObjs(1).YData;
dataObjs = findobj(fig,'-property','XData');
x2 = dataObjs(1).XData;
leg2 = findobj(fig,'type','legend');
legText2 = leg2.String{1};
% Ploting them in a new subplot
figure;subplot(2,1,1);
plot(x1,y1); axis tight;
legend(legText1);
title('Copied from fig1');
subplot(2,1,2);
plot(x2,y2); axis tight;
legend(legText2);
title('Copied from fig2');
Hope this helps!

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by