For Loop iteration only displays last plot in PPT slides
I created a code to display my plots onto a Powerpoint (PPT) slide. The issue lies with MATLAB would generate all the plots but would only display the last plot on all the PPT slides. So far the only method is to copy the for loop, change the range (ex: 1:1, 2:2, 3:3, etc) and the "plot.png" numerical. I want to eliminate this tedious method and have an easier method for each slide to display each corresponding plot.
In this example length(fileList) = 6. The fileList respresents the 6 plots generated in this example. Prior I had length(fileList) in the for loop but it would only display the last plot on the slides.
X1 = length(fileList);
for j = 1:1 %length(fileList)
imgFIG = openfig(strcat(fileList(j).folder,”,fileList(j).name));
saveas(imgFIG,’plot.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’, imgPNG3);
clearvars -except j pL ppt directory fileList dirSize X1
end
for j = 2:1:X1
imgFIG = openfig(strcat(fileList(j).folder,”,fileList(j).name));
saveas(imgFIG,’plot4.png’);
imgPNG = imread(‘plot4.png’);
imgPNG2 = imresize(imgPNG, 1.5);
imwrite(imgPNG2,’plot5.png’)
imgPNG3 = Picture(‘plot5.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);
clearvars -except j pL ppt directory fileList dirSize X1
end
close(ppt);
rptview(ppt);
endI created a code to display my plots onto a Powerpoint (PPT) slide. The issue lies with MATLAB would generate all the plots but would only display the last plot on all the PPT slides. So far the only method is to copy the for loop, change the range (ex: 1:1, 2:2, 3:3, etc) and the "plot.png" numerical. I want to eliminate this tedious method and have an easier method for each slide to display each corresponding plot.
In this example length(fileList) = 6. The fileList respresents the 6 plots generated in this example. Prior I had length(fileList) in the for loop but it would only display the last plot on the slides.
X1 = length(fileList);
for j = 1:1 %length(fileList)
imgFIG = openfig(strcat(fileList(j).folder,”,fileList(j).name));
saveas(imgFIG,’plot.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’, imgPNG3);
clearvars -except j pL ppt directory fileList dirSize X1
end
for j = 2:1:X1
imgFIG = openfig(strcat(fileList(j).folder,”,fileList(j).name));
saveas(imgFIG,’plot4.png’);
imgPNG = imread(‘plot4.png’);
imgPNG2 = imresize(imgPNG, 1.5);
imwrite(imgPNG2,’plot5.png’)
imgPNG3 = Picture(‘plot5.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);
clearvars -except j pL ppt directory fileList dirSize X1
end
close(ppt);
rptview(ppt);
end I created a code to display my plots onto a Powerpoint (PPT) slide. The issue lies with MATLAB would generate all the plots but would only display the last plot on all the PPT slides. So far the only method is to copy the for loop, change the range (ex: 1:1, 2:2, 3:3, etc) and the "plot.png" numerical. I want to eliminate this tedious method and have an easier method for each slide to display each corresponding plot.
In this example length(fileList) = 6. The fileList respresents the 6 plots generated in this example. Prior I had length(fileList) in the for loop but it would only display the last plot on the slides.
X1 = length(fileList);
for j = 1:1 %length(fileList)
imgFIG = openfig(strcat(fileList(j).folder,”,fileList(j).name));
saveas(imgFIG,’plot.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’, imgPNG3);
clearvars -except j pL ppt directory fileList dirSize X1
end
for j = 2:1:X1
imgFIG = openfig(strcat(fileList(j).folder,”,fileList(j).name));
saveas(imgFIG,’plot4.png’);
imgPNG = imread(‘plot4.png’);
imgPNG2 = imresize(imgPNG, 1.5);
imwrite(imgPNG2,’plot5.png’)
imgPNG3 = Picture(‘plot5.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);
clearvars -except j pL ppt directory fileList dirSize X1
end
close(ppt);
rptview(ppt);
end for loop, powerpoint, ppt, iteration, plot, multiple plot, matlab function, loop MATLAB Answers — New Questions