パワーポイントへのfigureの貼り付け

100 visualizzazioni (ultimi 30 giorni)
Mamoru Mabuchi
Mamoru Mabuchi il 22 Apr 2020
Risposto: Kojiro Saito il 23 Apr 2020
既存のパワーポイント資料へ、既存のスライドを指定してMATLABで書いたグラフ(figure)を貼り付けたいです。
どのようにすれば良いですか?

Risposte (3)

michio
michio il 23 Apr 2020
ちょうど Qiita に情報をまとめていたのでご紹介します。
MATLAB Report Generator があるとある程度シンプルに実現できます

Kenta
Kenta il 23 Apr 2020
こんにちは、関数printでできます。例えば、
clear;close all;clc
a=randn(100,4);
figure;boxplot(a)
print -clipboard -dmeta
とすれば、クリップボードに箱ひげ図が保存されていると思います。それをパワーポイントの画面で、ctrl+Vで張り付ければ良いです。
I=getframe(gcf);
imwrite(I.cdata,'boxplot.jpg')
ただ、パワーポイントに全ての図を張り付けるのではなく、最終的に好みの図のみを張り付ける状況もあるかと思います。
その場合は上のように、getframe関数で、figureの絵を取り出し、それをimwrite関数で画像として保存するのも良いかもしれません。ループごとにちがう名前で保存する場合は、sprintfなどを使って、ループでちがう名前を付けて、上書きされないようにすることが必要です。
また、getframeは他の場面でもいろいろと使えて汎用性が高い一方、2行書くので面倒かもしれません。その場合は下のように書けば1行で書けます。詳しくは下のURLをご参照ください。
print('boxplot2','-dpng')
  2 Commenti
Mamoru Mabuchi
Mamoru Mabuchi il 23 Apr 2020
回答ありがとうございます。
質問が不十分で申し訳ありません。
パワーポイントにグラフを貼り付ける下記の手順を、Mスクリプトで表現したいです。どのように記述すれば良いのか教えてください。
・既存のパワーポイントのファイルを開く
・グラフを貼り付けるパワーポイントのページ(スライド番号?)を指定する
・グラフを貼り付ける位置を指定する
・グラフを貼り付ける
Kenta
Kenta il 23 Apr 2020
なるほど、失礼いたしました。michioさまの回答がよさそうですね。そちらをご参照ください。よろしくお願いいたします。

Accedi per commentare.


Kojiro Saito
Kojiro Saito il 23 Apr 2020
Windows限定の方法になりますが、MATLAB本体の機能のCOM(actxserver)でできます。
例えば、以下のサンプルでは、カレントフォルダーにあるtest.pptxを開いて、スライド2の中心にFigureを貼り付けることができます。
% COMでパワポを起動
h = actxserver('PowerPoint.Application');
% test.pptxを開く
Presentation = h.Presentation.Open([pwd, filesep, 'test.pptx']);
% Figureを作成し、PNG画像で保存
figure;
plot(1:10)
figFile = [pwd filesep 'test1.png'];
print('-dpng','-r150', figFile)
% パワポのスライドの2ページ目を選択する
Slide1 = Presentation.Slides(1);
slideItem = Slide1.Item(2);
% スライドの幅と高さを取得する
slideWidth = Presentation.PageSetup.SlideWidth;
slideHeight = Presentation.PageSetup.SlideHeight;
% スライド2の中心に、Figureの画像を挿入する
imgWidth = 500; % 画像の横幅
imgHeight = 500; % 画像の高さ
Image1 = slideItem.Shapes.AddPicture(figFile, 'msoFalse', 'msoTrue', ...
slideWidth/2-imgWidth/2, slideHeight/2-imgHeight/2, imgWidth, imgHeight);
% パワポを同名で保存する
Presentation.Save
% COMのパワポを終了する
pause(1) %すぐに終了すると保存エラーが発生するので、1秒待たせています
h.Quit
h.delete
COMで操作できるパワポのオブジェクトは、下記のMicrosoftのドキュメントが参考になります。

Categorie

Scopri di più su MATLAB Report Generator in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!