How to save figures generated from function within a for loop?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nicholas Kavouris
le 14 Mar 2022
Commenté : Nicholas Kavouris
le 14 Mar 2022
i am looping over all data present in the desired folder, each loop of Extractdatafrom txt generates 3 figures and several arrays, how do i save only the figures generated from the function within the for loop? Would like to save them all to one specific folder as well
for i=1:length(unprocessed)
file_name=unprocessed(i).name;% get name of each file
[filepath,folder_name,ext]=fileparts(fullfile('R:','Matlab Analysis','1. To be Processed',file_name));%create proper file path with name of each file, create name for folder with data of completed analysis
[Temp_C, Temp_F, Auger_RPM, Auger_PWM, Fan_PWM]=ExtractDatafromtxt(file_path); %Extract Data From File
0 commentaires
Réponse acceptée
Walter Roberson
le 14 Mar 2022
savedir = fullfile('R:','Matlab Analysis','1. Processed');
if ~isfolder(savedir); mkdir(savedir); end
for i=1:length(unprocessed)
file_name = unprocessed(i).name;% get name of each file
[filepath,folder_name,ext] = fileparts(fullfile(unprocessed(i).folder, file_name));%create proper file path with name of each file, create name for folder with data of completed analysis
figs_before = findobj(groot, 'type', 'figure');
[Temp_C, Temp_F, Auger_RPM, Auger_PWM, Fan_PWM]=ExtractDatafromtxt(file_path); %Extract Data From File
figs_after = findobj(groot, 'type', 'figure');
figs_created = setdiff(figs_after, figs_before);
for J = 1 : length(figs_created)
savefile = fullfile(savedir, "figure_" + folder_name + "_" + J + ".fig");
savefit(figs_created(J), savefile);
end
close(figs_created);
end
1 commentaire
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Printing and Saving dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!