How to modify the size of images in a report
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Blue
il 15 Ott 2021
Modificato: Harikrishnan Balachandran Nair
il 20 Ott 2021
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 Commenti
Risposta accettata
Harikrishnan Balachandran Nair
il 20 Ott 2021
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);
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Images, Figures, Axes, Equations, MATLAB Code, and MATLAB Variables in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!