How to modify the size of images in a report
11 次查看(过去 30 天)
显示 更早的评论
Blue
2021-10-15
编辑: Harikrishnan Balachandran Nair
2021-10-20
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)
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Images, Figures, Axes, Equations, MATLAB Code, and MATLAB Variables 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!