Borrar filtros
Borrar filtros

For Loop iteration only displays last plot in PPT slides

3 visualizaciones (últimos 30 días)
Zack Morris
Zack Morris el 29 de Nov. de 2023
Comentada: Zack Morris el 8 de Dic. de 2023
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
  8 comentarios
Mathieu NOE
Mathieu NOE el 4 de Dic. de 2023
hello again
seems we are now both confused here .
1/ yes my code has nothing to do with yours , it's just an example how to use the suggested FEX submission to do the job - in my eyes, with little work on your side
2/ no , I am not asking for more code from your side , because I cannot help you there , as I cannot run it (I don't have the ReportGenerator Toolbox)
Zack Morris
Zack Morris el 4 de Dic. de 2023
Lol yea i think there was just misunderstanding.
  1. You think this is the only effective method to resolving my issue of the for loop only plotting the last generated plot on all the PPT slides?
  2. I'm looking at the exportToPPTX. Is there a way to add iteration so that i don't have to do "pptx.addSlide('Layout','Two Content');" continuously? I have other examples where I'll have to create 20+ slides.

Iniciar sesión para comentar.

Respuestas (1)

Constantino Carlos Reyes-Aldasoro
Constantino Carlos Reyes-Aldasoro el 6 de Dic. de 2023
Try using
drawnow
after view. It may just do the trick.
  4 comentarios
Constantino Carlos Reyes-Aldasoro
Constantino Carlos Reyes-Aldasoro el 8 de Dic. de 2023
Not sure I understand what the problem is, is it that the figure is not the correct size inside powerpoint? Or that the image is not exported with the correct dimensions?
Zack Morris
Zack Morris el 8 de Dic. de 2023
@Constantino Carlos Reyes-Aldasoro I'm just trying to implement a resizing command for the plots. Thy're just a little small on the PPT slides and I want to make them a little larger for easier visualization.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by