MATLAB: How do you import a .log file and put the information into various columns with headers

data import

Hello,
I have a .log file with the following type of text….
char=~=~=~=~=~=~=~=~=~= PuTTY log 2018.03.13 12:56:55 =~=~=~=~=~=~=~=~=~=~=~=
$GPRMC,115508,A,5338.5495,N,00146.6252,W,0.0,284.3,130318,3.6,W,A*13
$GPRMB,A,,,,,,,,,,,,V,A*1C
$GPGGA,115508,5338.5495,N,00146.6252,W,1,08,0.8,62.3,M,49.0,M,,*62
$GPGSA,A,3,04,,10,,,13,,17,19,20,24,28,0.0,0.8,0.8*35
$GPGSV,3,1,12,04,08,102,00,06,53,201,00,10,18,320,29,11,03,032,26*70
$GPGSV,3,2,12,12,09,202,25,13,51,131,40,15,74,202,25,17,21,103,34*77
$GPGSV,3,3,12,19,11,122,31,20,28,224,32,24,48,262,34,28,32,049,41*74
$GPGLL,5338.5495,N,00146.6252,W,115508,A,A*5D
$GPBOD,,T,,M,,*47
$GPVTG,284.3,T,287.9,M,0.0,N,0.0,K,A*2A
$HCHDG,187.3,,,3.6,W*33
$GPRTE,1,1,c,*37
I am stuck on how to extract all the data and have it in different columns. In this case I would like to have the data which is separated by commas to be inside a table but separated into different columns. At the moment I have used this line of code which puts it all inside one column:
% Open data file
fid=fopen('putty.log');
line=fgetl(fid);
k=1;
while ischar(line)
a{k,1}=line;
line=fgetl(fid);
k=k+1;
end
Any help/direction is appreciated.

Best Answer

>> [~,t]=xlsread('shem.csv'); % about the most easiest way to read csv with mixed data
>> t=t(2:end,:).'; % get rid of header line; transpose to column orientation
>> t(1,:)=strrep(t(1,:),'$',''); % turn names into allowable table names
>> cell2table(t(2:end,:),'VariableNames',t(1,:)) % and make a table
Error using cell2table (line 57)
Duplicate variable name: 'GPGSV'.
>>
OOOpsies!!! There are multiple columns with same name; can't turn into a table directly using those as names.
>> cell2table(t) % just make a table with default column names, then...
ans =
t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12
_______ _______ _______ ________ _______ _______ _______ _______ _______ _______ _______ _______
'GPRMC' 'GPRMB' 'GPGGA' 'GPGSA' 'GPGSV' 'GPGSV' 'GPGSV' 'GPGLL' 'GPBOD' 'GPVTG' 'HCHDG' 'GPRTE'
'' 'A' '' 'A' '' '' '' '' '' '' '' ''
'A' '' '' '' '' '' '' 'N' 'T' 'T' '' ''
'' '' 'N' '' '' '' '' '' '' '' '' 'c'
'N' '' '' '' '' '' '' 'W' 'M' 'M' '' '*37'
'' '' 'W' '' '' '' '' '' '' '' 'W*33' ''
'W' '' '' '' '' '' '' 'A' '*47' 'N' '' ''
'' '' '' '' '' '' '' 'A*5D' '' '' '' ''
'' '' '' '' '' '' '' '' '' 'K' '' ''
'' '' '' '' '' '' '' '' '' 'A*2A' '' ''
'' '' 'M' '' '' '' '' '' '' '' '' ''
'W' '' '' '' '' '' '' '' '' '' '' ''
'A*13' '' 'M' '' '' '' '' '' '' '' '' ''
'' 'V' '' '' '' '' '' '' '' '' '' ''
'' 'A*1C' '*62' '' '' '' '' '' '' '' '' ''
'' '' '' '' '' '' '' '' '' '' '' ''
'' '' '' '' '' '' '' '' '' '' '' ''
'' '' '' '0.8*35' '' '' '' '' '' '' '' ''
'' '' '' '' '' '' '' '' '' '' '' ''
'' '' '' '' '26*70' '34*77' '41*74' '' '' '' '' ''
>>
You'll have to decide what to do about the names depending on what need to do with the data; there's also a question as to what the stars mean in the data fields themselves as far as interpretation, but there's the data in an addressable format.