How to save figures generated from function within a for loop?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Nicholas Kavouris
el 14 de Mzo. de 2022
Comentada: Nicholas Kavouris
el 14 de Mzo. de 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 comentarios
Respuesta aceptada
Walter Roberson
el 14 de Mzo. de 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 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Printing and Saving en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!