Help with text file duplicate and concatenation

5 Ansichten (letzte 30 Tage)
mb1400
mb1400 am 19 Jun. 2013
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
  1 Kommentar
mb1400
mb1400 am 19 Jun. 2013
sorry like this
'$SDDBT......$GPGLL.....
'$SDDBT.......$GPGLL....

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 19 Jun. 2013
Bearbeitet: Azzi Abdelmalek am 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}

Weitere Antworten (2)

mb1400
mb1400 am 20 Jun. 2013
You are a Genius, thank you very much. You saved me days of work!!!!!!

mb1400
mb1400 am 20 Jun. 2013
Ok, Now I am stuck again. Sorry, I may be about to make a very easy question, but I have just started using matlab and starting manipulating string it's not the best. I have replaced the empty spaces in my strings with commas and now I would like to trim all the strings after the last coordinate to have something from this:
'$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'
To this:
'$SDDBT,00006.5,f,0002.0,M,0001.0,F*06,$GPGLL,5340.90756479,N,00713.79236750,E'
'$SDDBT,00006.8,f,0002.1,M,0001.1,F*0B,$GPGLL,5340.90609055,N,00713.79168827,E' '$SDDBT,00007.8,f,0002.4,M,0001.3,F*0D,$GPGLL,5340.90462662,N,00713.79106230,E'
I appreciate the help

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by