How to Save multiple files from a loop with separate names

9 ビュー (過去 30 日間)
MILLER BIGGELAAR
MILLER BIGGELAAR 2020 年 4 月 2 日
コメント済み: MILLER BIGGELAAR 2020 年 4 月 2 日
Hi guys,
Essentially I am running a loop which allows the user to select as many files as necessary, filter them and plot them agasint each other in one graph. The last task is to save the filtered data into a folder which I have created however I don't know how to do this. I think that the save command must have to exist within the loop but I want it to be able to save the filtered data as the original file name with 'Filtered_' as a prefix to it as well as saving it in a separate folder, any clue on what to do?
here is the program
for i = 1:length(list)
Data = load(list{i});
E = Data(:,1);
N = Data(:,2);
D = Data(:,3);
Eb = find(E>Filt_Elow);
UserE = E(Eb);
UserN = N(Eb);
UserD = D(Eb);
E = UserE;
N = UserN;
D = UserD;
Nb = find(N>Filt_Nlow);
UserE_1 = UserE;
UserN_1 = UserN;
UserD_1 = UserD;
UserE_1 = UserE(Nb);
UserN_1 = UserN(Nb);
UserD_1 = UserD(Nb);
figure(1)
plot3(UserE_1, UserN_1 ,UserD_1, '.')
hold on
end
% i was attempting to use Filename = list(i,:)
% and then save('Filtered_Data/Filtered_'(Filename))
Thanks

採用された回答

Walter Roberson
Walter Roberson 2020 年 4 月 2 日
Before the loop
outdir = 'Filtered_Data';
outprefix = 'Filtered_';
Inside the loop:
outfile = fullfile( outdir, [outprefix list{i}]);
save(outfile, 'UserE_1', 'UserN_1', 'UserD_1'); %change to appropriate list of variable names

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by