Resize Figure for Word report

조회 수: 24 (최근 30일)
Anne-Laure GUINET
Anne-Laure GUINET 2020년 3월 17일
댓글: Anne-Laure GUINET 2020년 3월 19일
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

채택된 답변

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

추가 답변 (2개)

Sean de Wolski
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:

Anne-Laure Guinet
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 !)
  댓글 수: 2
TJ Plummer
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);
Anne-Laure GUINET
Anne-Laure GUINET 2020년 3월 19일
Thanks, I've adjusted "manually" the good width and height and copy/paste ; it finally works !

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by