How do I insert *.png figures directly into a Report Generator word document?
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Richard Frühmann
am 7 Aug. 2018
Kommentiert: Rahul Singhal
am 21 Jun. 2019
I have a folder containing *.png images generated using a different program. I would like to insert these into a word document.
What I have done so far:
Following the "Getting Started" tutorial I imported two classes (or methods?):
import mlreportgen.report.*
import mlreportgen.dom.*
I created a report object:
rpt = Report('C:\reportpath\report','docx');
I created a section with a section title:
sec(1) = Section;
sec(1).Title = ['Test conducted using parameter 1: ' num2str(par(1)) ', and parameter 2: ' par(2)'];
And then I try to insert an image, and this is where I don't understand the documentation. My first attempt was:
fig1 = Image;
Error using mlreportgen.dom.Image
No constructor 'mlreportgen.dom.Image' with matching signature found.
My second attempt was:
fig1 = rptgen.cfr_image;
fig1.Image = srcfig1{7};
Unrecognized property 'Image' for class 'rptgen.cfr_image'.
My latest attempt was:
fig1 = rptgen.cfr_image;
fig1.FileName = 'figure1.png';
As this did not give me an error message I added it to the section / document:
add(sec(1),fig1); % insert figure into section
add(rpt,sec(1));
close(rpt);
What appears in the word document is just the text:
[1x1 rptgen.cfr_image]
Previously I tried using "imread" to read the image into the matlab workspace and then "imagesc" to plot it on a figure, but the quality was very poor. Hence I would like to insert the *.png file directly.
0 Kommentare
Akzeptierte Antwort
Rahul Singhal
am 20 Jun. 2019
Hi Richard,
Your first attempt, i.e., using the mlreportgen.dom.Image class, was the right way to add an image to the report. The error message states that you should also provide the path of the image file while instantiating an object of this class. See https://www.mathworks.com/help/rptgen/ug/mlreportgen.dom.image-class.html#buik4oj-3
Thanks,
Rahul
2 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!