Most efficient way for multiple dlmread executions

4 ビュー (過去 30 日間)
Evan Kias
Evan Kias 2012 年 12 月 2 日
コメント済み: Timothy Devenport 2015 年 3 月 11 日
Hi, I need to read several text files and assign variable names to the array located in each file. Currently, I simply copy and paste a list and edit the list to look like this:
syyr1_1 = dlmread('syyr1_1.his','',4,1);
syyr2_1 = dlmread('syyr2_1.his','',4,1);
syyr3_1 = dlmread('syyr3_1.his','',4,1);
syyr4_1 = dlmread('syyr4_1.his','',4,1);
syyr5_1 = dlmread('syyr5_1.his','',4,1);
syyr6_1 = dlmread('syyr6_1.his','',4,1);
syyr7_1 = dlmread('syyr7_1.his','',4,1);
syyr8_1 = dlmread('syyr8_1.his','',4,1);
syyr9_1 = dlmread('syyr9_1.his','',4,1);
syyr10_1 = dlmread('syyr10_1.his','',4,1);
As you can see, this method is extremely tedious. Is there a better way of doing this?
Thanks, Evan
  1 件のコメント
Evan Kias
Evan Kias 2012 年 12 月 2 日
For example, would you suggest reading all the files to one single array? Or, should I somehow change the variable name using the loop iteration number? I appreciate your input!

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

採用された回答

Walter Roberson
Walter Roberson 2012 年 12 月 2 日

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 12 月 2 日
編集済み: Azzi Abdelmalek 2012 年 12 月 2 日
for k=1:n
data{k}=dlmread(sprintf('syyr%d_1.his',k),",4,1);
end
There is no need to use multiple variables, a cell variable data contains all your data. For example, if you need data from 5 th file, it's data{5}
  1 件のコメント
Timothy Devenport
Timothy Devenport 2015 年 3 月 11 日
I have a similar problem, but your solution worked for me. I have another question though;
How do I address specific cells, say the end row, with your method?

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

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by