matlab report generator image with paragraph
5 次查看(过去 30 天)
显示 更早的评论
Hi, I use matlab report generator to report results from my gui. I have a lot of images and I need add a paragraphs under each of them. I tried one code, but it does not work. can you help me?
function vlozenie_mapy(handles,doc,ii)
import mlreportgen.dom.*
pic2=handles.pic(:,:,ii);
handles.poradie=handles.zaciatok+handles.krok*(ii-1);
nazov_obrazka=[handles.nazov '_MS_' num2str(handles.poradie) '_s' '.jpg'];
obrI=gray2ind(pic,256);
obrRGB=ind2rgb(obrI,jet(256));
imwrite(obrRGB,nazov_obrazka)
fileName = nazov_obrazka;
img = Image(fileName);
img.Width = '3cm';
img.Height = '3cm';
p = Paragraph( '', 'AR_Image' );
append(p, img);
append(doc, img);
p = Paragraph([handles.poradie,' s', 'AR_Caption']);
append(doc, p);
end
error Error using mlreportgen.dom.Document/append Cannot append object "dom.Paragraph:23506" of type "mlreportgen.dom.Paragraph" to inline hole "obr1". thanks for any help
0 个评论
回答(1 个)
Kausthub
2024-2-12
Hi Margareta,
I believe you would like to place an image with a paragraph using the MATLAB report generator. I belive the error the occurs because you are trying to append the image "img" to both the paragraph "p" and to the document "doc" directly. By removing either of them would resolve the error. I would suggest you to remove the line where you append the image to the paragraph.
append(p, img);
A snippet for the same:
import mlreportgen.dom.*;
d = Document('output','docx');
% Create image
x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y);
saveas(gcf,"myPlot_img.png");
plot1 = Image("myPlot_img.png");
plot1.Width = "4in";
plot1.Height = "4in";
% Add image
append(d,plot1);
% Create the paragraph
p = Paragraph(['Lorem ipsum dolor sit amet, consectetur adipiscing elit,' ...
' sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' ...
' Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris' ...
' nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in' ...
' reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla' ...
' pariatur. Excepteur sint occaecat cupidatat non proident, sunt in' ...
' culpa qui officia deserunt mollit anim id est laborum.']);
% Add paragraph
append(d,p);
close(d);
rptview(d.OutputPath);
Also, have attached a screenshot showing the output of the above code: an image with a paragraph.
Hope this helps!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!