打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Problem copying Matlab figure into Word

Thread Subject:
Problem copying Matlab figure into Word

Subject: Problem copying Matlab figure into Word

From: plmcelwee@yahoo.com (Phil)

Date: 14 Oct, 2004 12:40:37

Message: 1 of 8

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.

Subject: Problem copying Matlab figure into Word

From: us

Date: 14 Oct, 2004 15:47:38

Message: 2 of 8

Phil:
<SNIP is unhappy with his/her fig's quality in MS word...

> % Copy figure to Clipboard
> print(h1,'-dmeta');

a hint:

     print(h1,'-dmeta','-r300');

you might want to adjust the <rx> to your needs...

us

Subject: Problem copying Matlab figure into Word

From: Ken Davis

Date: 14 Oct, 2004 15:48:14

Message: 3 of 8

"Phil" <plmcelwee@yahoo.com> wrote in message
news:a3589d11.0410141140.7d867158@posting.google.com...
> 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.

I find that the -dbitmap switch on the print command gives me a better
picture than the -dmeta... but at a price.

Subject: Problem copying Matlab figure into Word

From: Murphy O'Brien

Date: 15 Oct, 2004 07:08:56

Message: 4 of 8

> "Phil" <plmcelwee@yahoo.com> wrote in message
> news:a3589d11.0410141140.7d867158@posting.google.com...
>> 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.
>>

Wow. I didn't know you could control other applictions like that!

I get very good quality using your code. Even at 500% zoom the lines
and fonts are all very smooth. I'm using Word 2002 and I tried both
Matlab 6.0 and 7.0.

If I just print to the clipboard with

print(h1,'dmeta')

and then Paste into Word manually, I also get great resolution. If I
paste into Paint Shop Pro, it asks me what resolution I would like at
Paste time.

If I paste into Microsoft Paint, I get crap resolution though. It
seems to be the destination application that determines the quality.
I did change the PasteSpecial to Paste and removed the parameters,
because with my Word, your Paste Special command tried to change and
save my Normal.Dot template.

A question for you. Where do you find help on the command parameters
like
invoke(word.Selection,'PasteSpecial',0,0,0,0,3);



Murphy.

Subject: Problem copying Matlab figure into Word

From: Martin Rickli

Date: 15 Oct, 2004 07:20:13

Message: 5 of 8

Hi
I'm happy with the following syntax:

% --- M-code ------------
% h1 is a figure handle
print_opt = sprintf('-f%d', h1 );
% Copy the figure window to the clipboard
print('-dmeta', print_opt);
% --- End ------------

Hope this helps
regards Martin
Martin.Rickli-at-mt-dot-com

us wrote:
>
>
> Phil:
> <SNIP is unhappy with his/her fig's quality in MS word...
>
>> % Copy figure to Clipboard
>> print(h1,'-dmeta');
>
> a hint:
>
> print(h1,'-dmeta','-r300');
>
> you might want to adjust the <rx> to your needs...
>
> us

Subject: Problem copying Matlab figure into Word

From: Yuyuan Gu

Date: 15 Oct, 2004 13:57:14

Message: 6 of 8

Hi, Phil,
It seems cool. However, I cannot make it run on my computer. I run
matlab r14 and office 10 under xp. When executing
invoke(word.Selection,'PasteSpecial',0,0,0,0,3);
I got this error message:
Invoke Error, Dispatch Exception:
Source: Microsoft Word
Description: The specified data type is unavailable.
Help File: C:\Program Files\Microsoft
Office\Office10\1033\wdmain10.chm
Help Context ID: 60f6
Do you know what is going on?
Y. Gu

Subject: Problem copying Matlab figure into Word

From: plmcelwee@yahoo.com (Phil)

Date: 17 Oct, 2004 20:28:30

Message: 7 of 8

> < ...A question for you. Where do you find help on the command parameters
> like invoke(word.Selection,'PasteSpecial',0,0,0,0,3); >

Murphy,

I don't fully understand the command parameters. I took this line of
code from someone's else code I found on the Internet, but there was
no explanation of the command parameters.

Subject: Problem copying Matlab figure into Word

From: plmcelwee@yahoo.com (Phil)

Date: 17 Oct, 2004 20:30:26

Message: 8 of 8

"Yuyuan Gu" <guyuyuan@hotmail.com> wrote in message news:<eeed0c3.4@webx.raydaftYaTP>...
> Hi, Phil,
> It seems cool. However, I cannot make it run on my computer. I run
> matlab r14 and office 10 under xp. When executing
> invoke(word.Selection,'PasteSpecial',0,0,0,0,3);
> I got this error message:
> ??? Invoke Error, Dispatch Exception:
> Source: Microsoft Word
> Description: The specified data type is unavailable.
> Help File: C:\Program Files\Microsoft
> Office\Office10\1033\wdmain10.chm
> Help Context ID: 60f6
> Do you know what is going on?
> Y. Gu

Yuyuan,

How did you copy to the clipboard? If you used the -dbitmap option
instead of -dmeta, you will get an error. If you use 'Paste' with no
parameters, then you can use either -dbitmap or -dmeta.

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Difference between clear, delete, and close
Rendering High Dynamic Range Images on the Web[Matlab B/S架构学习]
请问Matlab如何画多幅图
matlab 精确控制figure的大小
Automation :: Chapter 12: From COM to COM+ :: Part II: Delphi Object
Matlab,?VISIO,?Word间图形文件格式转换
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服