How to save figures generated from function within a for loop?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nicholas Kavouris
am 14 Mär. 2022
Kommentiert: Nicholas Kavouris
am 14 Mär. 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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 14 Mär. 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 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Printing and Saving finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!