Help with text file duplicate and concatenation
2 views (last 30 days)
Show older comments
Hello I have created a variable from a text file from which I have extrapolated
nuova_variabile =
'$SDDBT,00004.9,f,0001.5,M,0000.8,F*07'
'$GPGLL,5340.91664087,N,00713.79587546,E,073418.00,A,D*62'
'$GPGLL,5340.91360433,N,00713.79468132,E,073420.00,A,D*64'
'$SDDBT,00004.5,f,0001.4,M,0000.7,F*05004.5,f,0001.4,M,0000.7,F*02'
'$GPGLL,5340.91207731,N,00713.79413391,E,073421.00,A,D*63'
'$GPGLL,5340.91056222,N,00713.79354123,E,073422.00,A,D*6E'
'$SDDBT,00006.5,f,0002.0,M,0001.0,F*06'
'$GPGLL,5340.90756479,N,00713.79236750,E,073424.00,A,D*61'
'$SDDBT,00006.8,f,0002.1,M,0001.1,F*0B'
'$GPGLL,5340.90609055,N,00713.79168827,E,073425.00,A,D*66'
'$SDDBT,00007.8,f,0002.4,M,0001.3,F*0D'
'$GPGLL,5340.90462662,N,00713.79106230,E,073426.00,A,D*6C'
I would like to remove the $GPGLL duplicate when this happen in sequence, keeping only the first string to have something like this
'$SDDBT,00004.9,f,0001.5,M,0000.8,F*07'
'$GPGLL,5340.91664087,N,00713.79587546,E,073418.00,A,D*62'
'$SDDBT,00004.5,f,0001.4,M,0000.7,F*05004.5,f,0001.4,M,0000.7,F*02'
'$GPGLL,5340.91207731,N,00713.79413391,E,073421.00,A,D*63'
'$SDDBT,00006.5,f,0002.0,M,0001.0,F*06'
'$GPGLL,5340.90756479,N,00713.79236750,E,073424.00,A,D*61'
'$SDDBT,00006.8,f,0002.1,M,0001.1,F*0B'
'$GPGLL,5340.90609055,N,00713.79168827,E,073425.00,A,D*66'
'$SDDBT,00007.8,f,0002.4,M,0001.3,F*0D'
'$GPGLL,5340.90462662,N,00713.79106230,E,073426.00,A,D*6C'
and after that I would like to write a file were I have the $SDDBT and successive $GPGLL in a single line like this
'$SDDBT......$GPGLL..... '$SDDBT.......$GPGLL....
and so on.....
thanks in advance for you help
Manuela
Accepted Answer
Azzi Abdelmalek
on 19 Jun 2013
Edited: Azzi Abdelmalek
on 19 Jun 2013
b=char(nuova_variabile);
c=cellstr(b(:,1:6));
idx=strcmp(c,'$SDDBT')';
ii=[1 diff(idx)];
out=nuova_variabile(find(ii~=0))
% then add
ne=ceil(numel(out)/2)
out=cellfun(@(x,y) [x ' ' y],out(1:2:end), out(2:2:end),'un',0)
out{1}
0 Comments
More Answers (2)
See Also
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!