reading data with loop

3 ビュー (過去 30 日間)
Arnold Harms
Arnold Harms 2016 年 5 月 27 日
編集済み: TastyPastry 2016 年 5 月 27 日
Hey, I would like to read columns from datafiles (named 1.TXT to 129.TXT) with the 'textread' command. I tried this:
for i=1,129
filename = sprintf('%0d.TXT',i)
[a,b,c,d] = textread(filename,'%f%f%f%f')
end
... which does not work. Does anyone know, how I should write this loop?

回答 (1 件)

TastyPastry
TastyPastry 2016 年 5 月 27 日
編集済み: TastyPastry 2016 年 5 月 27 日
Your for loop declaration is wrong. Needs to be:
i=1:129
Try using textscan(), which can take in a file and a format and outputs a cell array. More here. textscan() offers several advantages over textread(), one of which is that it dumps data into a cell array rather than a bunch of variables.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by