Resize Figure for Word report
23 views (last 30 days)
Show older comments
Anne-Laure GUINET
on 17 Mar 2020
Commented: Anne-Laure GUINET
on 19 Mar 2020
Hello everybody,
I'm creating an app that generate a Word Report. I use a function inspired by Word_Example from MATLAB File Exchange. I've just modified some things to customize my report.
But when I use this to copy my figure (this is a part of my function CreateWord) :
figtoprint=figure(1); %opens new figure window
print(figtoprint,'-dmeta'); %print figure to clipboard
invoke(word.Selection,'Paste'); %paste figure to Word
close Figure
I have this on my Word document
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/277655/image.png)
Lot of white space and my fig is not complete...
My function CreateWorld is used in my mainScript named ReporActi (at the end). I generate my figure in this script, like this :
TAB(1)=figure;
uitable('Data',T{:,:},'ColumnName',T.Properties.VariableNames,...
'RowName',T.Properties.RowNames,'Units','Centimeters', 'Position',[0, 4, 15, 5]);
Thank you very much,
AL
0 Comments
Accepted Answer
TJ Plummer
on 17 Mar 2020
Edited: TJ Plummer
on 17 Mar 2020
One way to do it is to try different window sizes and when you find one that looks good in Word, simply use the get and set functions with 'Position' key. For example:
1) set a breakpoint after the figure is completed in Matlab. Then adjust the figure size using your mouse dragging the corner. A trial an error approach. use the Command Window to call:
pos = get(gcf, 'Position');
save('pos');
2) once you get the size you like, add in code after the figure is created:
load('pos');
set(gcf, 'Position', pos);
0 Comments
More Answers (2)
Sean de Wolski
on 18 Mar 2020
You should really consider using the MATLAB Report Generator. You can simply add, a figure to a Word report (no COM API etc.).
For example:
0 Comments
Anne-Laure Guinet
on 18 Mar 2020
Thanks TJ Plummer. But it doesn't work.It seems there is a confusion between
'Position' % Position of the figure named TAB(1)
'Position' % Position of the uitable
I have made this
TAB(1)=figure;
uitable('Data',T{:,:},'ColumnName',T.Properties.VariableNames,...
'RowName',T.Properties.RowNames,'Units','Normalized', 'Position',[0, 0, 1 ,1]);
% In the command Window
>> pos=get(TAB(1), 'Position')
pos =
680 558 560 420
Then after resize manually in the Figure window I get the new position (that I want)
pos=get(TAB(1), 'Position')
pos =
-1919 41 1920 963
TAB(1)=figure;
uitable('Data',T{:,:},'ColumnName',T.Properties.VariableNames,...
'RowName',T.Properties.RowNames);
set(TAB(1), 'Position',[-1919, 41, 1920, 963]);
I obtain this (that is worst than before !)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/277941/image.png)
2 Comments
TJ Plummer
on 18 Mar 2020
Hi Anne,
move
set(TAB(1), 'Position',[-1919, 41, 1920, 963]);
to before
uitable('Data',T{:,:},'ColumnName',T.Properties.VariableNames,...
'RowName',T.Properties.RowNames);
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!