Clear Filters
Clear Filters

Save files in different folder based on condition

1 view (last 30 days)
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

Accepted Answer

Voss
Voss on 20 Nov 2023
% 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

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!