picking up data file in each iteration
古いコメントを表示
hi every one;
i hope i can find a solution to my probem
i need to analyze 200 speech data files
they are saved in 200 data files .mat (ex: s1018.mat, s1028.mat .....and so on)
i want to analyze all these data files one by one
so how can automatically pick file in every itteration inside for loop ?
thanks
3 件のコメント
Fabio Freschi
2019 年 9 月 9 日
have names a particular sequence?
tareq ALTALMAS
2019 年 9 月 10 日
採用された回答
その他の回答 (4 件)
Bob Thompson
2019 年 9 月 9 日
1 投票
The best way I know how to do this is by listing all of the files using dir, and then looping through the files.
flist = dir('*.mat');
for i = 1:length(flist)
fi = open(flist(i).name); % Open file
...
end
Fabio Freschi
2019 年 9 月 10 日
編集済み: Fabio Freschi
2019 年 9 月 10 日
Following Stephen link
numFiles = 200;
for k = 1:numfiles
fileName = sprintf('s%d.mat', 1008+10*k);
data = load(fileName);
end
Assuming that all files can be reached with 1008+10*k
2 件のコメント
Fabio Freschi
2019 年 9 月 10 日
you are right, I just forgot to put the output variable! Thanks for pointing out.
Answer edited.
tareq ALTALMAS
2019 年 9 月 10 日
0 投票
4 件のコメント
Fabio Freschi
2019 年 9 月 10 日
What is wrong in the answers provided so far?
tareq ALTALMAS
2019 年 9 月 10 日
tareq ALTALMAS
2019 年 9 月 10 日
for i = 1
signal = s1018.mat
for i = 2
signal = s1028
and so on
You call repeating that 200 times "simple" ?
"i think if the file is in the current folder the load can do the work..."
The code I gave does not require the files to be in the current folder.
"... but in my way it is already in the workspace... "
How are you going to write code that accesses those 200 different variables? Loading directly into the workspace will lead to complex code. It will not be a good use of your time.
"...so i cannot use the load"
What on earth is stopping you from using load? MATLAB does not restrict how many times you import data.
"i need to ,ake signal = vector has the values inside s1018"
That is exactly what my answer gives you.
tareq ALTALMAS
2019 年 9 月 10 日
カテゴリ
ヘルプ センター および File Exchange で Historical Contests についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!