Read mat files from a custom function

1 回表示 (過去 30 日間)
pavlos
pavlos 2017 年 2 月 14 日
コメント済み: per isakson 2017 年 2 月 14 日
Hello,
Please help me with the following:
I need to create a function (m.file) that reads automatically mat files with different names.
For example,
Consider these mat files:
Day1_hour1.mat
Day1_hour2.mat
.
.
.
Day2_hour1.mat
Day2_hour2.mat
etc.
The function that I need should be like this:
function data=LoadData(n,m)
data=load('Dayn_hourm');
end
So for example, if I want to load
Day10_hour23
I would call
LoadData(10,23)
Thank you.
Best,
Pavlos
  1 件のコメント
per isakson
per isakson 2017 年 2 月 14 日
What do the mat-files contain? An identical set of variables?

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

採用された回答

per isakson
per isakson 2017 年 2 月 14 日
Try this
file_list = reshape( dir('Day*.mat'), 1,[] );
for saf = file_list
dh = sscanf( saf.name, 'Day%d_hour%d' );
data = load( saf.name );
LoadData{ dh(1), dh(2) } = data;
end
where the mat-files are in the current directory and are the only mat-files with names starting with the three letters "Day"

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by