Create figures with different number of images but same sizes

1 Ansicht (letzte 30 Tage)
Dominik
Dominik am 13 Jul. 2025
Kommentiert: Matt J am 14 Jul. 2025
I try to create 2 figures in 2 different scripts.
Script 1 looks like this:
img_sos = rand(64);
img_oar_pixel = rand(64);
img_oar_block = rand(64);
img_sos = img_sos / max(img_sos(:));
img_oar_pixel = img_oar_pixel / max(img_oar_pixel(:));
img_oar_block = img_oar_block / max(img_oar_block(:));
f = figure;
tl = tiledlayout(1, 3, 'TileSpacing', 'compact', 'Padding', 'compact');
clim1 = [0 1];
cmap1 = jet;
ax1 = [];
ax1(1) = nexttile;
imagesc(img_sos, clim1);
axis image off;
title('Sum-of-Squares', 'FontSize', 10);
ax1(2) = nexttile;
imagesc(img_oar_pixel, clim1);
axis image off;
title('Adaptive Kombination (Pixelweise)', 'FontSize', 10);
ax1(3) = nexttile;
imagesc(img_oar_block, clim1);
axis image off;
title('Adaptive Kombination (Blockweise)', 'FontSize', 10);
set(ax1, 'Colormap', cmap1);
cb1 = colorbar(ax1(end), 'eastoutside');
cb1.Label.String = 'Normierte Signalintensität';
cb1.Label.FontSize = 10;
cb1.Ticks = 0:0.2:1;
My second script looks like this:
figure; %<---Matt J added
img_oar_rec = rand(64);
img_oar_rec = img_oar_rec/max(img_oar_rec(:));
img_mask = rand(64);
tiledlayout(1, 2, 'TileSpacing', 'compact', 'Padding', 'compact');
ax1 = nexttile;
imagesc(img_oar_rec, [0 1]);
axis image off;
colormap(ax1, 'jet');
cb = colorbar;
cb.Label.String = 'Normierte Signalintensität';
cb.Label.FontSize = 10;
title('Adaptive Kombination', 'FontSize', 10);
ax2 = nexttile;
imagesc(img_mask);
axis image off;
colormap(ax2, 'gray');
title('Binäre Maske', 'FontSize', 10);
As I want to use these figures in a latex report, I want to save these figures as jpg.
But in both figures, the images should have the same size. Same for the titles and colorbar strings.
How can I do that? I should not scale figures in latex.
  1 Kommentar
Matt J
Matt J am 13 Jul. 2025
Bearbeitet: Matt J am 13 Jul. 2025
What's wrong with the code as is? The images (within each figure) look the same size to me.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Matt J
Matt J am 13 Jul. 2025
Bearbeitet: Matt J am 13 Jul. 2025
If you mean you want a common image size across all axes in both figures, I think the best that you can do is relocate both layouts to a common master figure. The relocation can be done automatically, as below.
You can then make cropped copies of the master figure in MSWord or PowerPoint to achieve separate figures.
%% Create initial figures
tl1=fig1();
tl2=fig2();
%% Relocate to master figure
figure('Position',[ 34 137 1245 813]);
ax=[flip(tl1.Children);flip(tl2.Children)];
ax=findobj(ax,'Type','axes');
TL=tiledlayout(2,3,'TileSpacing', 'compact', 'Padding', 'compact');
for i=1:numel(ax)
ax(i).Parent=TL;
ax(i).Layout.Tile=i;
end
close([tl1.Parent,tl2.Parent])
function tl=fig1()
img_sos = rand(64);
img_oar_pixel = rand(64);
img_oar_block = rand(64);
img_sos = img_sos / max(img_sos(:));
img_oar_pixel = img_oar_pixel / max(img_oar_pixel(:));
img_oar_block = img_oar_block / max(img_oar_block(:));
f = figure;
tl = tiledlayout(1, 3, 'TileSpacing', 'compact', 'Padding', 'compact');
clim1 = [0 1];
cmap1 = jet;
ax1 = [];
ax1(1) = nexttile;
imagesc(img_sos, clim1);
axis image off;
title('Sum-of-Squares', 'FontSize', 10);
ax1(2) = nexttile;
imagesc(img_oar_pixel, clim1);
axis image off;
title({'Adaptive Kombination';'(Pixelweise)'}, 'FontSize', 10);
ax1(3) = nexttile;
imagesc(img_oar_block, clim1);
axis image off;
title({'Adaptive Kombination';'(Blockweise)'}, 'FontSize', 10);
set(ax1, 'Colormap', cmap1);
cb1 = colorbar(ax1(end), 'eastoutside');
cb1.Label.String = 'Normierte Signalintensität';
cb1.Label.FontSize = 10;
cb1.Ticks = 0:0.2:1;
end
function tl=fig2()
figure; %<---Matt J added
img_oar_rec = rand(64);
img_oar_rec = img_oar_rec/max(img_oar_rec(:));
img_mask = rand(64);
tl=tiledlayout(1, 2, 'TileSpacing', 'compact', 'Padding', 'compact');
ax1 = nexttile;
imagesc(img_oar_rec, [0 1]);
axis image off;
colormap(ax1, 'jet');
cb = colorbar;
cb.Label.String = 'Normierte Signalintensität';
cb.Label.FontSize = 10;
title('Adaptive Kombination', 'FontSize', 10);
ax2 = nexttile;
imagesc(img_mask);
axis image off;
colormap(ax2, 'gray');
title('Binäre Maske', 'FontSize', 10);
end
  4 Kommentare
dpb
dpb am 14 Jul. 2025
Differences probably come from the size of label fields; perhaps if controlled the format to be consistent across all...
Matt J
Matt J am 14 Jul. 2025
Go for it, but I think it'll be more trouble than it's worth.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by