read specific column of text file using Matlab
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
Star Strider
le 14 Mai 2015
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 commentaires
Walter Roberson
le 14 Mai 2015
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 commentaires
Voir également
Catégories
En savoir plus sur Data Import and Export dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!