Include two separated existing matlab figures into a new subplot

2 ビュー (過去 30 日間)
Enrico Gambini
Enrico Gambini 2021 年 8 月 25 日
回答済み: TADA 2021 年 8 月 25 日
Hello everyone!
I know that this topic was already discussed a lot (see https://it.mathworks.com/matlabcentral/answers/101806-how-can-i-insert-my-matlab-figure-fig-files-into-multiple-subplots#answer_111153), but i really would like not just to copy axes and lines into the new subplot, but also other features such as legends, grids and titles.
Hope that the question is clear
Thank you!

回答 (2 件)

TADA
TADA 2021 年 8 月 25 日
you can always save the figure as an image and plot the two images
fig1 = openfig('figure1.fig');
print(fig1, '-dtiff', '-r300', hapFigPath('figure1.tif'));
fig2 = openfig('figure2.fig');
print(fig2, '-dtiff', '-r300', 'figure2.tif');
fig3 = figure();
ax(1) = axes('Position', [0.01, 0.01, 0.48, 0.98]);
im1 = imread('figure1.tif');
imshow(im1);
ax(2) = axes('Position', [0.51, 0.01, 0.48, 0.98]);
im2 = imread('figure2.tif');
imshow(im2);
  1 件のコメント
Enrico Gambini
Enrico Gambini 2021 年 8 月 25 日
That can help a little bit, but my question was about putting every feature of each figure into a new subplot containing those figures.

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


TADA
TADA 2021 年 8 月 25 日
fig1 = genFig(101);
fig2 = genFig(102);
fig3 = figure('Position', [100, 100, 900, 500]);
pnlLeft = uipanel(fig3, 'Position', [0 0 0.5 1]);
pnlRight = uipanel(fig3, 'Position', [0.5 0 0.5 1]);
children = fig1.Children;
for i=numel(children):-1:1
children(i).Parent = pnlLeft;
end
children = fig2.Children;
for i=numel(children):-1:1
children(i).Parent = pnlRight;
end
function fig = genFig(n)
x = linspace(-10, 10)';
y = [sin(x), x.^-3, x.^3];
fig = figure(n);
clf(fig);
sui.setPos(fig, [100, 100, 400, 500], 'pixels');
plot(x, y);
legend('sin(x)', 'x.^-3', 'x.^3', 'Location', 'SouthEast');
end

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by