Filter löschen
Filter löschen

Last Saved .PNG uploaded on all PPT slides

2 Ansichten (letzte 30 Tage)
Zack Morris
Zack Morris am 4 Dez. 2023
Kommentiert: Zack Morris am 6 Dez. 2023
For some reason my code would only upload my last saved .png file on all my PPT generated slides. I don't have this issue if i make a for loop for each image but that'd be too tedious. My code is supposed to upload each saved plot onto separate PPT slides.
Does the issue lie in the replace() function or the for loop statement? I labeled below
The code:
a = fileLength; % fileLength = 6 in this example
for j = 3:length(a) %The issue may lie here
imgFIG = openfig(strcat(fileList(j).folder,'\',fileList(j).name));
saveas(imgFIG,'plot6.png');
imgPNG = imread('plot6.png');
imgPNG2 = imresize(imgPNG, 1.5);
imwrite(imgPNG2,'plot7.png')
imgPNG3 = Picture('plot7.png');
fName = fileList(j).name;
z = fName(27:28);
dataSlides = add(ppt,'Title and Content');
newTitle = strcat('Step', {' '}, z,' Simulations');
replace(dataSlides,'Title', newTitle);
replace(dataSlides,'Content', imgPNG3); %The issue may lie here
clearvars -except j pL ppt directory fileList dirSize a
end

Antworten (1)

Image Analyst
Image Analyst am 4 Dez. 2023
What does this line do:
dataSlides = add(ppt,'Title and Content');
What is ppt? I'd use ActiveX if you're using Windows.
Why are you calling clearvars? I'd get rid of that. It's not necessary.
And if
a = fileLength; % fileLength = 6 in this example
then
1:length(a)
so the loop only happens once because length(6) = 1. The length of a scalar is just one value. Try
for j = 3: a % For j = 3, 4, 5, and 6
  5 Kommentare
Image Analyst
Image Analyst am 5 Dez. 2023
I don't think I can help more unless I have the full code, like where you instantiate ppt.
Can you use ActiveX (i.e. are you on Windows and willing to use it)?
Zack Morris
Zack Morris am 6 Dez. 2023
Thank you. Using what you said for j and the bottom 2 lines fixed the photo issue on each PPT slide.
for j = 1:a
imgFIG = openfig(strcat(fileList(j).folder,'\',fileList(j).name));
saveas(imgFIG,['plot' num2str(j) '.png']);
imgPNG = Picture(['plot' num2str(j) '.png']);
%imgPNG = imread('plot.png');
%imgPNG2 = imresize(imgPNG, 1.5);
%imwrite(imgPNG2,'plot2.png')
%imgPNG3 = Picture('plot2.png');
fName = fileList(j).name;
z = fName(27:28);
dataSlides = add(ppt,'Title and Content');
newTitle = strcat('Step', {' '}, z,' Simulations');
replace(dataSlides,'Title', newTitle);
replace(dataSlides,'Content', imgPNG);
end
My new issue is resizing the images. I tried using the imresize command with imgPNG but no result. Any assistance?

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by