How to modify the size of images in a report

35 ビュー (過去 30 日間)
Blue
Blue 2021 年 10 月 15 日
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)

採用された回答

Harikrishnan Balachandran Nair
Harikrishnan Balachandran Nair 2021 年 10 月 20 日
編集済み: Harikrishnan Balachandran Nair 2021 年 10 月 20 日
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);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Report Generator Task Examples についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by