필터 지우기
필터 지우기

Help with text file duplicate and concatenation

조회 수: 2 (최근 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 CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by