Rank: 297105 based on 0 downloads (last 30 days) and 0 file submitted
photo

Mel

E-mail

Personal Profile:
Professional Interests:

 

Watch this Author's files

 

Comments and Ratings by Mel View all
Updated File Comments Rating
12 Aug 2009 saveppt This function saves Matlab figure windows or Simulink models to a Powerpoint file. Author: Mark Brown

I don't know if it is a bug (can't find it in the database) but it seems that when copying through the clipboard using the .emf option, dashed lines in the figures get converted into normal. This is irritating!

Everything works fine however if you do it by saving first the figure into an .emf file and then use Insert Picture->From File in PowerPoint to import the figure.

This can be done automatically by modyfing saveppt.m to save the figure into a temporary emf-file instead of the Clipboard.
1.Change the lines
% Capture current figure/model into clipboard:
print('-dmeta', prnopt);
to
% Save current figure/model into a temporary emf-file
emffile = fullfile(fpath, 'resfig.emf');
print('-dmeta', prnopt, emffile);
2. Change
% Paste the contents of the Clipboard:
pic1 = invoke(new_slide.Shapes,'Paste');
to
% Insert the contents of the emf-file
pic1 = invoke(new_slide.Shapes,'AddPicture',emffile,true,true,0,0,...
slide_W,slide_H);
% Delete the temporary file
delete(emffile);

12 Aug 2009 saveppt This function saves Matlab figure windows or Simulink models to a Powerpoint file. Author: Mark Brown

A correction:). Adding ppt.delete does not solve the problem of the activeX server running ahead on itself as I claimed in my last comment:).

There is though a simple solution which also makes export of many figures much faster. Just give an array of figure handles as an additional argument to the function and move the loop over the figures into the application. Something like

function savepptmany(filespec, figvec, titletext, prnopt)
[...]
% Start an ActiveX session with PowerPoint:
ppt = actxserver('PowerPoint.Application');

if ~exist(filespec,'file');
% Create new presentation:
op = invoke(ppt.Presentations,'Add');
else
% Open existing presentation:
op = invoke(ppt.Presentations,'Open',filespec,[],[],0);
end

% Loop over figures
for addfig = 1:length(figvec)
figure(figvec(addfig));

% Capture current figure/model into clipboard:
if nargin<3
print -dmeta
else
print('-dmeta',prnopt)
end

% Get current number of slides:
slide_count = get(op.Slides,'Count');

% Add a new slide (with title object):
slide_count = int32(double(slide_count)+1);
new_slide = invoke(op.Slides,'Add',slide_count,11);

[...]
% Center picture on page (below title area):
set(pic1,'Left',single((double(slide_W) - double(pic_W))/2));
set(pic1,'Top',single(double(slide_H) - double(pic_H)));
end

if ~exist(filespec,'file')
% Save file as new:
invoke(op,'SaveAs',filespec,1);
else
% Save existing file:
invoke(op,'Save');
end
[...]
Note that titletxt has to be cell array of strings now.

29 May 2009 saveppt This function saves Matlab figure windows or Simulink models to a Powerpoint file. Author: Mark Brown

I am not en expert in ActiveX but adding
ppt.delete;
in the end of saveppt.m seems to solve the problem of running ahead of itself when saving many images. Excellent application!

Contact us