code to load my files from folder, add workspace variable and save to another folder
3 次查看(过去 30 天)
显示 更早的评论
Dears,
I have a lot of .mat files wich I want to add a variable fs=128 to all of the one by one.
one way is to load ech other, add variable and save, which takes some days because of thousands data.
so I need a code (i.e. for loop) to load each one, add same variable and save it.
please help me.
thank you.
0 个评论
采纳的回答
Stephen23
2020-10-22
编辑:Stephen23
2020-10-22
fs = 128;
for ... loop over all files, you need to finish this line yourself!
fnm = 'name_of_the_file.mat'; % change this depending on how you generate/index the filenames.
save(fnm,'fs','-append')
end
3 个评论
Stephen23
2020-10-22
编辑:Stephen23
2020-10-22
"it is not work"
You will need to actually loop over the files using one of the methods shown in the documentation:
For example, something like this:
fs = 128;
D = 'absolute or relative path to the folder where the files are saved'; % !!! YOU NEED TO CHANGE THIS !!!
S = dir(fullfile(D,'*.mat'));
for 1:numel(S)
fnm = fullfile(D,S(k).name);
save(fnm,'fs','-append')
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Adding custom doc 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!