PowerPoint へ画像を貼り付けるに​はどのようにすればよ​いですか?

57 views (last 30 days)
MathWorks Support Team
MathWorks Support Team on 20 Sep 2013
MATLAB コマンドで、 Figure の図などを PowerPoint に貼り付ける方法を教えてください。

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Apr 2023
Edited: MathWorks Support Team on 19 Apr 2023
下記のいずれかの方法で実現することが可能です。
1. MATLAB エディタの変換機能を用いる方法
2. COM の機能を用いる方法
1. MATLAB エディタの変換機能を用いる方法
MATLAB エディタでは、エディタ上に記述されたコードおよび、それらのコードを実行することで表示される Figure を HTML や PowerPoint などの形式に変換し、出力する機能があります。
以下の手順により、PowerPoint 形式にコードおよび Figure の結果を出力することができます。
1) MATLAB エディタに以下のようなコードを記述します。
a = 1:10;
b = [1:10].^2;
plot(a,b,'b.')
2) エディタのメニューから、[ファイル]-> [○○○.m に対する構成を変換]->[○○○.mに対する変換の構成を編集]を選択します。
3) [出力ファイル形式] で "ppt" を選択します。
4) [変換] ボタンを押します。
なおこの方法では、PowerPoint のスライドにおけるコードや、Figure の図の位置を制御することはできませんが、セル(%%)定義により、別々のスライドに出力することは可能です。
%% 第1章
% テスト1
a = 1:10;
b = [1:10].^2;
plot(a,b,'b.')
%% 第2章
% テスト2
x = 1:10;
y = randn(size(x));
plot(x,y)
2. COM の機能を用いる方法
COM の規約に沿った ActiveX オートメーション機能を利用し、MATLAB から Microsoft PowerPoint にデータを出力します。ここでは、MATLAB をクライアントとして、Microsoft PowerPoint をサーバとして通信を行います。
%% PowerPointを開く
h = actxserver('PowerPoint.Application')
% PowerPointのウィンドウを表示
h.Visible = 1;
h.Help
%% プレゼンテーションを追加
h.Presentation.invoke
Presentation = h.Presentation.Add
%% スライドを追加
% PowerPoint2003 の場合
Presentation.Slides.invoke
Slide1 = Presentation.Slides.Add(1,'ppLayoutBlank')
Slide2 = Presentation.Slides.Add(2,'ppLayoutBlank')
%
% PowerPoint2007, 2010 の場合
% blankSlide = Presentation.SlideMaster.CustomLayouts.Item(1)
% Slide1 = Presentation.Slides.AddSlide(1,blankSlide)
% Slide2 = Presentation.Slides.AddSlide(2,blankSlide)
%% イメージを描画
% <full path>の部分でパスを指定してください
figure;
plot(1:10)
print('-dpng','-r150','<full path>\test1.png')
figure;
image(ceil(64*rand(20,20)))
print('-dpng','-r150','<full path>\test2.png')
%% スライドへイメージを挿入
Image1 = Slide1.Shapes.AddPicture('<full path>\test1.png','msoFalse','msoTrue',100,20,500,500)
Image2 = Slide2.Shapes.AddPicture('<full path>\test2.png','msoFalse','msoTrue',100,20,500,500)
Title1 = Slide1.Shapes.AddTextbox('msoTextOrientationHorizontal',200,10,400,70)
Title1.TextFrame.TextRange.Text = 'plot(1:10)'
Title2 = Slide2.Shapes.AddTextbox('msoTextOrientationHorizontal',200,10,400,70)
Title2.TextFrame.TextRange.Text = 'image(ceil(64*rand(20,20)))'
%% プレゼンテーションを保存
Presentation.SaveAs('C:\...\ExamplePresentation.ppt')
%% PowerPointを閉じる
h.Quit;
h.delete;
なお、ユーザコミュニティである MATLAB Central では、MATLAB Figure や Simulink モデルを PowerPoint に出力するプログラムが公開されています。
・MATLAB Central: saveppt
ただし、MATLAB Centralにおいてフリーで公開されているファイルの内容に関しましては、直接プログラム作成者の方にお問い合わせください。

More Answers (0)

Categories

Find more on スクリプト in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!