필터 지우기
필터 지우기

Save files in different folder based on condition

조회 수: 1 (최근 30일)
Jorge Luis Paredes Estacio
Jorge Luis Paredes Estacio 2023년 11월 20일
답변: Voss 2023년 11월 20일
Hello, I have several signals that are the output as text files (which contain different information after the signal processing which could be named as the matrix A for simplification) and they have different flags based on the results obtained after processing each individual data. As an example, let us say the following.
Processedfile1: flag 1=0, Flag2=0, Flag 3=0 (This does have any issue)
Processedfile2: flag 1=1, Flag2=0, Flag 3=0 (This have an issue in MATLAB coding and needs implementation)
Processedfile3: flag 1=1, Flag2=0, Flag 3=1 (This should be discarded)
.
.
.
Processed file n: flag 1=0, Flag2=0, Flag 3=0 (This does now have any issue)
Therefore, based on the output of each signal, they should be saved as text files in a sulbfolder (where the functions and data are located) or different folder outside the current one (Disk drive D inside a folder) like this:
Inside the folder or subfolder "Unflagged_folder": Processedfile1.txt, Processedfilen.txt.
Inside the folder or subfolder "Flagged_folder": Processedfile3.txt
Inside the folder or subfolder "Implement_code_for this case": Processedfile2.txt
Thank your for your help

채택된 답변

Voss
Voss 2023년 11월 20일
% define your sub/folder locations, using absolute or relative paths:
ok_folder = 'Unflagged_folder';
implement_folder = 'Implement_code_for this case';
discard_folder = 'Flagged_folder';
% loop over files:
for ii = 1:n
% ...
% generate matrix A and flag1, flag2, flag3 for file ii
% ...
% select the correct folder, based on the values of flag1, flag2, flag3:
% (the actual logic you use may be different than this)
if flag3
folder = discard_folder;
elseif flag1
folder = implement_folder;
else
folder = ok_folder;
end
% write matrix A to file:
filename = fullfile(folder,sprintf('Processedfile%d.txt',ii));
writematrix(A,filename);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by