for loop for matlab files

4 ビュー (過去 30 日間)
Rica
Rica 2014 年 9 月 2 日
編集済み: Evan 2014 年 9 月 2 日
Hi all, i have a group of M-files. they ara named in this manner:
%
M1.m
M2.m
.
.
.
how could i read these files inn a loop?
thak you all

採用された回答

Evan
Evan 2014 年 9 月 2 日
編集済み: Evan 2014 年 9 月 2 日
% where N is the number of files
for i = 1:N
load(['M' num2str(N) '.m'])
end
This will change based on whether or not you know how many of these files exist (if not, look into using the dir command) and how you want them to be stored (if they're all identically named variables but differ in size, I would suggest a structure; if they're the same size, you could just use a higher-dimension matrix).

その他の回答 (1 件)

Iain
Iain 2014 年 9 月 2 日
Ugh. The curse of eval strikes again.
That'll run them in a loop, but god help anyone trying to debug it.
for i = 1:m
eval(['M' num2str(i)])
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by