Resize Figure for Word report
23 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
TJ Plummer
2020-3-17
编辑:TJ Plummer
2020-3-17
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 个评论
更多回答(2 个)
Sean de Wolski
2020-3-18
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 个评论
Anne-Laure Guinet
2020-3-18
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 个评论
TJ Plummer
2020-3-18
Hi Anne,
move
set(TAB(1), 'Position',[-1919, 41, 1920, 963]);
to before
uitable('Data',T{:,:},'ColumnName',T.Properties.VariableNames,...
'RowName',T.Properties.RowNames);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!