How to put existing figures in one figure together in case labels are also existing?

2 vues (au cours des 30 derniers jours)
I have two existing figures ('0001.fig" and "0002.fig"), and want to put in one figure together vertically.
Due to the "Class labes", it is difficult.
Thank you,
openfig('0001.fig')
ans =
Figure (1) with properties: Number: 1 Name: '' Color: [1 1 1] Position: [233 144 560 420] Units: 'pixels' Use GET to show all properties
openfig('0002.fig')
ans =
Figure (2) with properties: Number: 2 Name: '' Color: [1 1 1] Position: [232 146 560 420] Units: 'pixels' Use GET to show all properties

Réponse acceptée

Angelo Yeo
Angelo Yeo le 12 Juin 2024
fig1 = openfig('0001.fig');
ax1 = findobj(fig1, 'type', 'axes');
cb1 = findobj(fig1, 'type', 'colorbar');
cmap1 = colormap(ax1);
fig2 = openfig('0002.fig');
ax2 = findobj(fig2, 'type', 'axes');
cb2 = findobj(fig2, 'type', 'colorbar');
cmap2 = colormap(ax2);
% A new figure and make it tile-layouted
newFig = figure;
t = tiledlayout(2, 1);
% copy axes from the first figure
nexttile(t);
new_ax1 = gca;
copyobj(allchild(ax1), new_ax1);
title(new_ax1, get(get(ax1, 'Title'), 'String'));
% copy the colorbar 1
if ~isempty(cb1)
new_cb1 = colorbar(new_ax1, 'Position', cb1.Position);
set(new_cb1, 'Limits', cb1.Limits, 'Ticks', cb1.Ticks, 'Location', cb1.Location, 'Color', cb1.Color, 'TickLabels', cb1.TickLabels);
colormap(new_ax1, cmap1)
grid on;
end
% copy axes from the second figure
nexttile(t);
new_ax2 = gca;
copyobj(allchild(ax2), new_ax2);
title(new_ax2, get(get(ax2, 'Title'), 'String'));
grid on;
% copy the colorbar 2
if ~isempty(cb2)
new_cb2 = colorbar(new_ax2, 'Position', cb2.Position);
set(new_cb2, 'Limits', cb2.Limits, 'Ticks', cb2.Ticks, 'Location', cb2.Location, 'Color', cb2.Color, 'TickLabels', cb1.TickLabels);
colormap(new_ax2, cmap2)
end
% close original figures
close(fig1);
close(fig2);
  2 commentaires
Mibang
Mibang le 12 Juin 2024
This is not that simple, thanks a lot!
Angelo Yeo
Angelo Yeo le 12 Juin 2024
It's mostly about copying the properties from original figures. That's why it got long. Happy to help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Exploration dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by