R2009 matlab powerpoint functions

I am having getting erros due top what i think having an older version of matlab.. the section that opens and adds figures to the powerpoint to woirk in older matlab 2009 version
%Powerpoint function
import mlreportgen.ppt.*
% Check if PowerPoint is running
[status, result] = system('tasklist /FI "IMAGENAME eq Powerpnt.exe"');
is_running = contains(result, 'Powerpnt.exe');
if is_running
if exist('Plotted Circulator', 'file')==0
system('taskkill /F /IM POWERPNT.EXE');
end
else
end
fsize = 6;
%trial plots
x = 0:pi/10:2*pi;
y = sin(x);
y2 = sin(x-0.25);
y3 = sin(x-0.5);
%this loop sets the characterictics fo the plot and saves plot to png file
%in numerical order
while k <= fsize
%initializes figure
figure('Name','Measured Data','NumberTitle','off');
%initializes figure size and position on screen
xwidthfig = 450;
ywidthfig = 350;
xwidthscr = 650;
ywidthscr = 650;
%figure characteristics
h = figure(k);
set(gcf,'PaperPositionMode','auto')
set(h, 'Position',[xwidthscr ywidthscr xwidthfig ywidthfig])
%plots sample figures
plot(x,y,'b',x,y2,'r--o',x,y3,'g*');
%saves figures to png format
saveas(gcf,sprintf('fig%d.png', k));
%increases counter for loops
k = k +1;
%powerpoint loop
if k > fsize
k =1;
%%%%%% this section
ppt = Presentation('Plotted figures');
open(ppt)
while k <= fsize
img = Picture(sprintf('fig%d.png',k));
s(k) = add(ppt,'Title and Picture');
replace(s(k),'Title',' Figure');
replace(s(k),'Picture',img);
k = k +1;
end
close(ppt);
close all;
continue
end
end
%deletes png created to avoid memory overload
delete *.png
%View the presentation
rptview(ppt);

6 Comments

Where exactly are you getting an error and what is the full error message?
contains() is much newer than your release.
%%%%%% this section is the concern but yeah i am sure contains is an
%%%%%% isues as well.. im not too concern on the system running
%%%%%% validation i can change that process.. i am more stuck on
%%%%%% opening processing picutes and closing the powerpoint
ppt = Presentation('Plotted figures');
open(ppt)
while k <= fsize
img = Picture(sprintf('fig%d.png',k));
s(k) = add(ppt,'Title and Picture');
replace(s(k),'Title',' Figure');
replace(s(k),'Picture',img);
k = k +1;
end
close(ppt);
close all;
i found this that does what i need and i believe it is good for older versions.
the problem is that it crashes when it tries to add a second slide any pointesr would be helpful
g = actxserver('powerpoint.application');
% Open PowerPoint and make it visible
g.Visible = 1;
Presentation = g.Presentation;
% Prompt the user for the PowerPoint file to amend
[fn, pn] = uigetfile('*.ppt', 'Select PowerPoint File To Amend');
filename = fullfile(pn, fn); %changed
Presentation = invoke(Presentation, 'open', filename);
% Get current number of slides
slide_count = get(Presentation.Slides, 'Count');
% Export all PNGs in the current directory to the PowerPoint file specified
% above. The following slides will be added to the END of the PowerPoint
% file. All slides will have a common title.
for i=1:length(files)
slide_count = int32(double(slide_count)+1);
slide = invoke(Presentation.Slides, 'Add', slide_count(i), 11); %crashes here after the first run
set(slide.Shapes.Title.Textframe.Textrange, 'Text', 'SomeTitle');
slidefile = fullfile(project_dir, files(i).name); %new
Image{i} = slide.Shapes.AddPicture(slidefile, 'msoFalse', 'msoTrue', 0, 80, 720, 440); %changed
end
error says it exceeds the number of array elements
slide_count = get(Presentation.Slides, 'Count');
That is a scalar.
slide_count = int32(double(slide_count)+1);
You increment the slide count scalar by 1.
slide = invoke(Presentation.Slides, 'Add', slide_count(i), 11); %crashes here after the first run
but there you try to index that scalar slide_count at index i.

Sign in to comment.

Answers (0)

Asked:

on 5 Apr 2023

Commented:

on 6 Apr 2023

Community Treasure Hunt

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

Start Hunting!