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

24 Ansichten (letzte 30 Tage)
I have searched for several questions which partly does this, but I don't manage to do it all.
  1 Kommentar
Walter Roberson
Walter Roberson am 6 Nov. 2019
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Subhadeep Koley
Subhadeep Koley am 6 Nov. 2019
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!

Kategorien

Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by