MATLAB: Skipping characters in a data file while keeping numbers

read data

I have a large database of .txt files that are giving me some problems when I try to read them in. I have looked at the official MATLAB help pages (for those who are just going to refer me to those) and I have not made too much progress. The format of the text files is below. The data that I need is in columns 2,3,6,7. I have tried using textscan and textopen to read in the whole file but only column 1 gets imported "IO" and the rest show up as [] with no data. The other problem that I foresee is removing the characters from columns 6 'N' and 7 'E' while still retaining the numbers. Any advice would be greatly appreciated, thanks!
IO, 02, 1951061018, , BEST, 0, 182N, 682E,-999
IO, 02, 1951061100, , BEST, 0, 187N, 681E,-999
IO, 02, 1951061106, , BEST, 0, 192N, 679E,-999
IO, 02, 1951061112, , BEST, 0, 197N, 676E,-999
IO, 02, 1951061118, , BEST, 0, 203N, 674E,-999
IO, 02, 1951061200, , BEST, 0, 208N, 671E,-999

Best Answer

--- R2012a ---
'ascii_letters_numbers.txt' contains your sample text. This code reads and converts the text according to the format string, frm. Don't ask me why "E" ends up as "e".
The problem is to get the format string right.
%IO, 02, 1951061200, , BEST, 0, 208N, 671E,-999
frm = '%s%f%f%s%s%f%f%c%f%c%f';
fid = fopen( 'ascii_letters_numbers.txt', 'r' );
cac = textscan( fid, frm, 'Delimiter', ',' );
fclose( fid );
>> cac{10}
ans =
e
e
e
e
e
e
>>
--- Skipping characters ---
You modify the format string to skip columns. To skip #column 1,4,5 and the last use
frm = '%*s%f%f%*s%*s%f%f%c%f%c%*f';
Related Question