Resize Figure for Word report

24 visualizaciones (últimos 30 días)
Anne-Laure GUINET
Anne-Laure GUINET el 17 de Mzo. de 2020
Comentada: Anne-Laure GUINET el 19 de Mzo. de 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

Respuesta aceptada

TJ Plummer
TJ Plummer el 17 de Mzo. de 2020
Editada: TJ Plummer el 17 de Mzo. de 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);

Más respuestas (2)

Sean de Wolski
Sean de Wolski el 18 de Mzo. de 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 el 18 de Mzo. de 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 comentarios
TJ Plummer
TJ Plummer el 18 de Mzo. de 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 el 19 de Mzo. de 2020
Thanks, I've adjusted "manually" the good width and height and copy/paste ; it finally works !

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB Report Generator en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by