Resize Figure for Word report

25 Ansichten (letzte 30 Tage)
Anne-Laure GUINET
Anne-Laure GUINET am 17 Mär. 2020
Kommentiert: Anne-Laure GUINET am 19 Mär. 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
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

Akzeptierte Antwort

TJ Plummer
TJ Plummer am 17 Mär. 2020
Bearbeitet: TJ Plummer am 17 Mär. 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);

Weitere Antworten (2)

Sean de Wolski
Sean de Wolski am 18 Mär. 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:

Anne-Laure Guinet
Anne-Laure Guinet am 18 Mär. 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 !)
  2 Kommentare
TJ Plummer
TJ Plummer am 18 Mär. 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);
Anne-Laure GUINET
Anne-Laure GUINET am 19 Mär. 2020
Thanks, I've adjusted "manually" the good width and height and copy/paste ; it finally works !

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB Report Generator finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by