Problem copying Matlab figure into Word
winggundam :: all :: 電腦知識
第1頁(共1頁)
回復: Problem copying Matlab figure into Word
I have having difficulty automating the process of copying
Matlab-generated figures into Word. Manually it works fine when in
the Figure menu I select 'Copy Figure' and then paste into Word.
Doing this gets me a nice high-quality copy of the figure in Word.
The problem though is when I try to automate it. When I automate it
using the lines of code shown below, I get a lower quality copy of the
figure where the text on the figure is very difficult to read.
Here are the lines of code I am using:
% Generate data and plot
for i=1:100
y(i) = log(i);
end
h1 = figure; plot (y,i);
text(4.9,10,'text1 = 0.9999','HorizontalAlignment','right');
% Open link to Word
word = actxserver('Word.Application');
% Create new Word document
op = invoke(word.Documents,'Add');
% Find end of document and make it the insertion point
end_of_doc = get(word.activedocument.content,'end');
set(word.application.selection,'Start',end_of_doc);
set(word.application.selection,'End',end_of_doc);
% Copy figure to Clipboard
print(h1,'-dmeta');
% Paste figure to Word document (use PasteSpecial instead of Paste
% because I want to disable 'Float Over Text')
invoke(word.Selection,'PasteSpecial',0,0,0,0,3);
% Save file
filename = 'C:\temp\temp.doc';
invoke(op,'SaveAs',filename,1);
% Close application window
invoke(op,'Close');
% Quit MS Word
invoke(word,'Quit');
Does anyone know how I can modify this code to get a better quality
copy of the figure into Word? If I could get a copy of the figure
that looks like the copy I get when manually selecting Copy Figure'
from the Figure window, that would be ideal.
Matlab-generated figures into Word. Manually it works fine when in
the Figure menu I select 'Copy Figure' and then paste into Word.
Doing this gets me a nice high-quality copy of the figure in Word.
The problem though is when I try to automate it. When I automate it
using the lines of code shown below, I get a lower quality copy of the
figure where the text on the figure is very difficult to read.
Here are the lines of code I am using:
% Generate data and plot
for i=1:100
y(i) = log(i);
end
h1 = figure; plot (y,i);
text(4.9,10,'text1 = 0.9999','HorizontalAlignment','right');
% Open link to Word
word = actxserver('Word.Application');
% Create new Word document
op = invoke(word.Documents,'Add');
% Find end of document and make it the insertion point
end_of_doc = get(word.activedocument.content,'end');
set(word.application.selection,'Start',end_of_doc);
set(word.application.selection,'End',end_of_doc);
% Copy figure to Clipboard
print(h1,'-dmeta');
% Paste figure to Word document (use PasteSpecial instead of Paste
% because I want to disable 'Float Over Text')
invoke(word.Selection,'PasteSpecial',0,0,0,0,3);
% Save file
filename = 'C:\temp\temp.doc';
invoke(op,'SaveAs',filename,1);
% Close application window
invoke(op,'Close');
% Quit MS Word
invoke(word,'Quit');
Does anyone know how I can modify this code to get a better quality
copy of the figure into Word? If I could get a copy of the figure
that looks like the copy I get when manually selecting Copy Figure'
from the Figure window, that would be ideal.
lung- Admin
- 文章數 : 26067
注冊日期 : 2009-07-12
回復: Problem copying Matlab figure into Word
> % Copy figure to Clipboard
> print(h1,'-dmeta');
a hint:
print(h1,'-dmeta','-r300');
you might want to adjust the <rx> to your needs...
> print(h1,'-dmeta');
a hint:
print(h1,'-dmeta','-r300');
you might want to adjust the <rx> to your needs...
lung- Admin
- 文章數 : 26067
注冊日期 : 2009-07-12
回復: Problem copying Matlab figure into Word
word = actxserver('Word.Application');
word.Visible = 1;
op = invoke(word.Documents,'Add');
active=word.ActiveDocument;
%% Table 1
% Create 4x4 table
range=word.Selection.Range;
shapes=word.Selection.InlineShapes;
t=invoke(word.ActiveDocument.Tables,'add',range,2,2);
% fill each cell with an image, image will fit to table
invoke(shapes,'addpicture',fullfile(pwd, 'fig1.wmf'));
invoke(word.Selection,'moveright',1,1);
invoke(shapes,'addpicture',fullfile(pwd, 'fig2.wmf'));
invoke(word.Selection,'moveright',1,2);
invoke(shapes,'addpicture',fullfile(pwd, 'fig3.wmf'));
invoke(word.Selection,'moveright',1,1);
invoke(shapes,'addpicture',fullfile(pwd, 'fig4.wmf'));
%% Table 2, I want this on a new page
invoke(word.Selection,'InsertBreak',2); % how do I get the next stuff on a new page?
range=word.Selection.Range;
shapes=word.Selection.InlineShapes;
t=invoke(word.ActiveDocument.Tables,'add',range,1,2);
invoke(shapes,'addpicture',fullfile(pwd, 'fig1.wmf'));
invoke(word.Selection,'moveright',1,1);
invoke(shapes,'addpicture',fullfile(pwd, 'fig2.wmf'));
http://stackoverflow.com/questions/5467769/how-do-i-insert-multiple-figures-into-multiple-tables-in-matlab
word.Visible = 1;
op = invoke(word.Documents,'Add');
active=word.ActiveDocument;
%% Table 1
% Create 4x4 table
range=word.Selection.Range;
shapes=word.Selection.InlineShapes;
t=invoke(word.ActiveDocument.Tables,'add',range,2,2);
% fill each cell with an image, image will fit to table
invoke(shapes,'addpicture',fullfile(pwd, 'fig1.wmf'));
invoke(word.Selection,'moveright',1,1);
invoke(shapes,'addpicture',fullfile(pwd, 'fig2.wmf'));
invoke(word.Selection,'moveright',1,2);
invoke(shapes,'addpicture',fullfile(pwd, 'fig3.wmf'));
invoke(word.Selection,'moveright',1,1);
invoke(shapes,'addpicture',fullfile(pwd, 'fig4.wmf'));
%% Table 2, I want this on a new page
invoke(word.Selection,'InsertBreak',2); % how do I get the next stuff on a new page?
range=word.Selection.Range;
shapes=word.Selection.InlineShapes;
t=invoke(word.ActiveDocument.Tables,'add',range,1,2);
invoke(shapes,'addpicture',fullfile(pwd, 'fig1.wmf'));
invoke(word.Selection,'moveright',1,1);
invoke(shapes,'addpicture',fullfile(pwd, 'fig2.wmf'));
http://stackoverflow.com/questions/5467769/how-do-i-insert-multiple-figures-into-multiple-tables-in-matlab
lung- Admin
- 文章數 : 26067
注冊日期 : 2009-07-12
回復: Problem copying Matlab figure into Word
img = imread('figure.jpg');
read figure into Matlab
read figure into Matlab
lung- Admin
- 文章數 : 26067
注冊日期 : 2009-07-12
winggundam :: all :: 電腦知識
第1頁(共1頁)
這個論壇的權限:
您 無法 在這個版面回復文章