フィルターのクリア

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 Center および File ExchangeWhos についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by