フィルターのクリア

Using for loop to load multiple mat files of different names

1 回表示 (過去 30 日間)
Sarah
Sarah 2012 年 9 月 19 日
回答済み: André 2013 年 9 月 26 日
Hey guys, I have a number of .mat files that I would like to load and run specific commands on. This is the code I have so far, but I am not sure if I have set it up properly. How can I autonomously load a number of files through the for loop command?
Incl is a 1x64 cell array which contains the name of the .mat file in each cell. So for example, (1,1) = filename1, (2,1) = filename2, etc etc. Here is my code:
Incl{J,1} = DIR(Ind(1,J)).name;
for K = 1:length(Ind)
StrSpec = Incl(K,1);
load(StrSpec)
*command1
*command2
...
*commandN
end
Thanks for your help! :)

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 9 月 19 日
編集済み: Azzi Abdelmalek 2012 年 9 月 19 日
for k=1:numel(INCL)
file=INCL{k}
data=load(file)
% if yoour data are x y z then data is a struct varaiable, data.x data.y data.z
%code
end
  1 件のコメント
Sarah
Sarah 2012 年 9 月 19 日
Worked! Thanks a lot...my problem was that I wasn't using the cell array to define file = INCL{k}

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

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2012 年 9 月 19 日

André
André 2013 年 9 月 26 日
Hi there
Actually I wanted to ask for a solution for a similar problem. But It just turned out that it works after having corrected an syntax error. So perhaps my solution can be useful for others, too.
If you want to load several .mat-datasets with a similar name (dataset1.mat, dataset2.mat, ...) into matlab and use them for a function in a for-loop, the following should be helpful:
for k = 1:n;
C = strcat('dataname',num2str(n),'.mat');
load(C);
desiredfunction(C);
end

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by