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

3 ビュー (過去 30 日間)
Nicholas Kavouris
Nicholas Kavouris 2022 年 3 月 14 日
コメント済み: Nicholas Kavouris 2022 年 3 月 14 日
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 Center および File ExchangePrinting and Saving についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by