How to load all .mat files in a folder and save accordingly?

1 回表示 (過去 30 日間)
bio lim
bio lim 2015 年 7 月 1 日
コメント済み: bio lim 2015 年 7 月 1 日
I am trying to run some code on bunch of .mat files with different names which are not in sequence (only the starting parts are same). They are all located in a folder called 'data', and I want to run my program on each one of them and save accordingly to a different folder called 'results'. The name of my .mat files are in the following format.
SSR_******, where there are random numbers in the asterisks.
Can anyone help me with this? Thanks.

採用された回答

Walter Roberson
Walter Roberson 2015 年 7 月 1 日
resultsdir = 'results';
dinfo = dir('SSR_****.mat');
for K = 1 : length(dinfo)
thisfile = dinfo(K).name;
destfile = fullfile(resultsdir, thisfile);
thisdata = load(thisfile);
thisdata.z = thisdata.X.^2 + thisdata.Y.^2; %do something with the stored variables
save(destfile, '-struct', 'thisdata'); %save all the vars
end
  1 件のコメント
bio lim
bio lim 2015 年 7 月 1 日
Saves hours of work. Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by