add multiple new files to powerpoint with differen images within a for loop and mlreportgen.ppt in matlab

To add multiple new files to PowerPoint with different images within a for loop and mlreportgen.ppt in Matlab, you can follow these steps:

  1. Open the PowerPoint file in Matlab using ppt = mlreportgen.ppt.Presentation('path/to/file.pptx');
  2. Create a for loop where you iterate through your list of image files. Within the loop, create a new slide using slide = add(ppt,'Title and Content');.
  3. Add the image to the slide using replace(slide,'Content',Picture('path/to/image.jpg'));. You can change the 'path/to/image.jpg' to be the file path of the image you want to insert on each iteration of the loop.
  4. Repeat step 3 for each image you want to add to the slide.
  5. Repeat steps 2-4 for each slide you want to add to the PowerPoint file.

Here is an example implementation of the above steps:

main.m
ppt = mlreportgen.ppt.Presentation('path/to/file.pptx');

imageFiles = ["path/to/image1.jpg", "path/to/image2.jpg", "path/to/image3.jpg"];

for i = 1:length(imageFiles)
    slide = add(ppt,'Title and Content');
    replace(slide,'Content',Picture(imageFiles(i)));
end

close(ppt);
281 chars
11 lines

This code will create a new slide for each image in the imageFiles list and insert the corresponding image onto the slide. Finally, it will close the PowerPoint file.

gistlibby LogSnag