How to Save multiple files from a loop with separate names
9 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!