MATLAB: Resize Figure for Word report

figureMATLAB

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
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

Best Answer

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);