How to modify the size of images in a report

39 visualizzazioni (ultimi 30 giorni)
Hello,
I am struggling to add images of the correct size in a report (https://www.mathworks.com/matlabcentral/answers/1563981-how-to-increase-the-size-of-figures-in-report-generator?s_tid=srchtitle). So I thought I would try a different route by using Document instead of Report and saving the figures in the correct size and importing them back in with the same size. As shown below this doesnt work; why is the image in the document below so huge ? I thought I was saving it as a 4x4 inches image. Why is it that img.Height and img.Width dont seem to do anything ?
Thank you,
import mlreportgen.report.*
import mlreportgen.dom.*
rpt = Document('test', 'pdf');
open(rpt)
x = [1 2 3 4];
y = [2 4 6 8];
t = tiledlayout(2, 1, 'Padding', 'tight');
t.Units = 'inches';
t.OuterPosition = [0.25 0.25 4 4];
nexttile;
scatter(x, y);
nexttile;
scatter(log(x), log(y))
set(gcf, 'Units', 'inches', 'Position', [0.25 0.25 4 4])
exportgraphics(t, 'test.jpg', 'Resolution', 300)
img = Image('test.jpg');
img.Height = '4in';
img.Width = '4in';
img.Style = {HAlign("center")};
append(rpt, img);
close(rpt)

Risposta accettata

Harikrishnan Balachandran Nair
Modificato: Harikrishnan Balachandran Nair il 20 Ott 2021
Hi,
I understand that you are trying to modify the size of the image before appending it to your document.
The height and width property are contained inside the cell array "img.Style". Hence, when you change the alignment after setting the 'height' and 'width', the height and width are again set to the default value. You can instead use the following code for your implementation.
import mlreportgen.report.*
import mlreportgen.dom.*
rpt = Document('test', 'pdf');
open(rpt)
x = [1 2 3 4];
y = [2 4 6 8];
t = tiledlayout(2, 1, 'Padding', 'tight');
t.Units = 'inches';
t.OuterPosition = [0.25 0.25 4 4];
nexttile;
scatter(x, y);
nexttile;
scatter(log(x), log(y))
set(gcf, 'Units', 'inches', 'Position', [0.25 0.25 4 4])
exportgraphics(t, 'test.jpg','Resolution',300);
img = Image('test.jpg');
img.Style = {Height('4in'),HAlign("center"),Width('4in')};
append(rpt, img);
close(rpt);

Più risposte (0)

Categorie

Scopri di più su MATLAB Report Generator Task Examples in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by