Save files in different folder based on condition
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!