CB-Frequency-Coding-of-Motor-Kinematics / Supporting Functions / F_convert2PPT.m
F_convert2PPT.m
Raw
function F_convert2PPT()
% This function convert all .fig files inside the root to image
% files and set up a PowerPoint template.
tic
% list figures in the current folder

w = dir('*.fig');

% Create a presentation
import mlreportgen.ppt.*
% ppt = Presentation(append(datestr(datetime('today')),".pptx"));
ppt = Presentation("Freq_vs_TremorFreq.pptx");

% convert all figures to the specified format
for i = 1:length(w)
    filename = char(w(i).name);
    target_name = filename(1:end-4); % exclude file extension
    
    % Add a slide to the presentation
    open(ppt);
    slide = add(ppt,"Title and Content");
    replace(slide,"Title",filename);
    
    % load file as image
    fig = openfig(filename);
    

    
    % Print the figure to an image file
%     saveas(fig,target_name,'meta');
    figSnapshotImage = [sprintf('%s', target_name),'.png'];
    print(fig,"-dpng",figSnapshotImage);
    

    
    % Create a Picture object using the figure snapshot image file
%     figPicture = Picture([target_name '.emf']);
    figPicture = Picture(figSnapshotImage);
    
    % Add the figure to the slide
    replace(slide,"Content",figPicture);
    
    close all;
    clear fig slide;
    
end
% close(ppt);

% View the presentation
rptview(ppt);

toc
end