read specific column of text file using Matlab
1 回表示 (過去 30 日間)
古いコメントを表示
My text file looks like the following text:
69.600000, 56.500000, 19991101, 0, 16.000000, 1, 5,3GGXC6,UCTP, 792,, 69.4139, 56.5321, 20725.632, 26267346, 7.33496,/Net/tholia/qscat/data/nc_test_daily/1999/qs_l2b_1999305.nc, 935, 71
It is the first line of my text file. The rest of lines of the text file has same format I'm trying to read specific column of this text file by using Matlab, but it contains number and string.So How to get certain column of this text file? Need some help to solve this problem. Thanks
0 件のコメント
回答 (2 件)
Star Strider
2015 年 5 月 14 日
If all the rows of your file are of the same format, the textscan function could probably read it. You would use the ‘format specification’ to choose the column to read.
0 件のコメント
Walter Roberson
2015 年 5 月 14 日
colpos = 42; %starting column example
colwid = 7; %column width example
regpat = sprintf('^(?:.{%d}).{%d}', colpos-1, colwid);
filestr = fileread('YourTextFile.txt'); %read file into string
colcontents = regexp(filestr, regpat, 'match', 'lineanchors');
colcontents will now be a cell array of strings, one per entry per line, containing whatever characters were in those columns. If appropriate you can process the cell array further such as by using str2double(colcontents) if you want to interpret them as numbers.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Import and Export についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!