Help with text file duplicate and concatenation

4 ビュー (過去 30 日間)
mb1400
mb1400 2013 年 6 月 19 日
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 件のコメント
mb1400
mb1400 2013 年 6 月 19 日
sorry like this
'$SDDBT......$GPGLL.....
'$SDDBT.......$GPGLL....

サインインしてコメントする。

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 6 月 19 日
編集済み: Azzi Abdelmalek 2013 年 6 月 19 日
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}

その他の回答 (2 件)

mb1400
mb1400 2013 年 6 月 20 日
You are a Genius, thank you very much. You saved me days of work!!!!!!

mb1400
mb1400 2013 年 6 月 20 日
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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by