필터 지우기
필터 지우기

How to save figures generated from function within a for loop?

조회 수: 1 (최근 30일)
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

채택된 답변

Walter Roberson
Walter Roberson 2022년 3월 14일
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
Nicholas Kavouris
Nicholas Kavouris 2022년 3월 14일
Thank you! Works like a charm!
is there any way to save the files as a larger size? Currently looking to save the files as a .pdf, but upon completion the code returns files which are only half the size of the sheet as seen below, would like them to be larger and more readable
within the function code the figures are coded as
PID_Performance=figure('Name','PID Performance','WindowState','maximized','Visible','off');

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by