Hi
I've a .txt file with over 50000 lines(exact number of lines unknown) with 20 parameters(in line 1, the rest of the lines are data). I need to get two different parameters(column number 2 and number 12) from it. How can I do this the smartest way?

 採用された回答

dpb
dpb 2014 年 6 月 3 日
編集済み: dpb 2014 年 6 月 3 日

0 投票

By current memory, that's not all that big any longer...probably just as easy to just load the file and then trash the columns don't need/want...
Many possible choices...
x=importdata('yourfile.txt','headerlines',1); % read the file
x=x(:,[2 12]); % keep only the columns wanted
Alternatively, only read the two columns...
fmt=['%*f %f' repmat('%*f',1,9) '%f' repmat('%*f',1,8]); % a format string
x=textread('yourfile.txt',fmt,'headerlines',1); % read 'em in...
Many variations of the above are possible...see
help iofun
for list of all the i/o functions; choose from one of the above or from the list the one that strikes your fancy for the file format...

2 件のコメント

hmtrondheim Tróndhiem
hmtrondheim Tróndhiem 2014 年 6 月 3 日
When I use the first method I get an error message saying: Index exceeds matrix dimensions. What can I do about that?
dpb
dpb 2014 年 6 月 3 日
編集済み: dpb 2014 年 6 月 4 日
Make sure importdata works to begin with.
Show your exact code and result of
whos x
afterwards as well as
exist('yourfile.txt','file')
Wouldn't hurt to paste a short section of the file just to make sure we know what we're talking about...

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Import and Analysis についてさらに検索

質問済み:

2014 年 6 月 3 日

編集済み:

dpb
2014 年 6 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by