필터 지우기
필터 지우기

Is there an example of using MATLAB to create PowerPoint slides?

조회 수: 209 (최근 30일)
Is there a way, from MATLAB, to write images and content directly into PowerPoint slides? Do you have any examples of how to do this?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2019년 2월 5일
There are three options for using MATLAB R2018b to create PowerPoint slides.
1. Use the "Publish To" option in the MATLAB Editor. Consider an MATLAB script file in the MATLAB Editor, for example:
a = [1:10];
b = [1:10].^2;
plot(a,b,'b.')
In the MATLAB Editor menu, choose "File" -> "Publish To". You have your choice of HTML, XML, LaTeX, Word Document, or PowerPoint presentation. An advantage of this option is simplicity; a disadvantage is that you do not have full control of the output format.
2. Use the MATLAB Report Generator. This approach allows greater control over the resulting file, though it should be noted that the MATLAB Report Generator is not part of base MATLAB. A simple PowerPoint presentation can be created as follows:
import mlreportgen.ppt.*
slides = Presentation('myFirstPresentation');
add(slides,'Title Slide');
contents = find(slides,'Title');
replace(contents(1),'My First Presentation');
close(slides);
More options using the MATLAB Report Generator can be found here:
This functionality, using the Report Generator PowerPoint API, was introduced in MATLAB R2015b.
3. Open PowerPoint as a COM Automation server (Windows platforms only). See attached example. In considering this example, please note that it was tested only with Office 2003 on a 32-bit Windows XP platform.
  댓글 수: 2
Brad
Brad 2016년 1월 18일
This has been an excellent example to follow when attempting to get MATLAB to interact with PowerPoint. And so far, I've had a lot of success in adding PNG files to and existing PowerPoint presentation. But I do have one question: When adding a new slide to an existing presentation, I can't seem to control the title font size. I'm using 2015a with PowerPoint 2010. Could I be running into a limitation of some kind?
Rahul Singhal
Rahul Singhal 2020년 10월 20일
편집: Rahul Singhal 2020년 10월 24일
Don, you can print the MATLAB figures, using print or saveas, to an image file and then use mlreportgen.ppt.Picture API to include that snapshot in a presentation using Report Generator. Below is an example:
% Create a presentation
import mlreportgen.ppt.*
ppt = Presentation("myFigurePresentation.pptx");
open(ppt);
% Add a slide to the presentation
slide = add(ppt,"Title and Content");
% Add title to the slide
replace(slide,"Title","surf(peaks)");
% Create a MATLAB figure with the surface plot
fig = figure;
surf(peaks);
% Print the figure to an image file
figSnapshotImage = "figSnapshot.png";
print(fig,"-dpng",figSnapshotImage);
% Create a Picture object using the figure snapshot image file
figPicture = Picture(figSnapshotImage);
% Add the figure snapshot picture to the slide
replace(slide,"Content",figPicture);
% Close the presentation
close(ppt);
% Once the presentation is generated, the figure and the image file
% can be deleted
delete(fig);
delete(figSnapshotImage);
% View the presentation
rptview(ppt);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by