How to center Image

34 次查看(过去 30 天)
I have an image object of the type mlreportgen.dom.Image and I want to center it but I don't know how to do it. I tried with HAlign but it doesn't work and gives me the error and indeed the align property doesn't seem to be there in the Image documentation...
Unable to perform assignment because dot indexing is not supported for variables of this type.
My code is:
PlotImg = Image(path);
PlotImg.Style = {Height('6in')};
PlotImg.Style = {HAlign('center')}; % that gives an error
add(SectionPASS, PlotImg);
So what should I do to center this Image in my report ?
Thank you in advance.

采纳的回答

Rahul Singhal
Rahul Singhal 2019-6-28
Hi Jack,
I am not sure about the error, but in your code you are overriding the Style property value of the Image. So the Height format will not be honored. To concatenate the formats in the Style property, I would suggest:
PlotImg.Style = {Height('6in'), HAlign('center')};
Or
PlotImg.Style = {Height('6in')};
PlotImg.Style = [PlotImg.Style {HAlign('center')}];
Also, I tried with a sample script and was able to align the image to the center using the HAlign format.
import mlreportgen.dom.*
d = Document('output','pdf');
image = Image(which('ngc6543a.jpg'));
image.Style = {Height('2in'), HAlign('center')};
append(d, image);
close(d);
rptview(d);
Thanks,
Rahul

更多回答(0 个)

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by