Hello! I need to extract the lines which start with PG10 from this text file. Could you please help me. Thanks! I would use while loop but I am not sure how.

4 ビュー (過去 30 日間)
Ôªø#cP2011  4 19  0  0  0.00000000      96 ORBIT IGS08 HLM  IGS
## 1632 172800.00000000   900.00000000 55670 0.0000000000000
+   32   G01G02G03G04G05G06G07G08G09G10G11G12G13G14G15G16G17
+        G18G19G20G21G22G23G24G25G26G27G28G29G30G31G32  0  0
+          0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
+          0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
+          0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
++         4  2  2  2  2  2  2  2  2  2  2  2  2  2  3  2  2
++         2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  0  0
++         0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
++         0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
++         0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
%c G  cc GPS ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc
%c cc cc ccc ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc
%f  1.2500000  1.025000000  0.00000000000  0.000000000000000
%f  0.0000000  0.000000000  0.00000000000  0.000000000000000
%i    0    0    0    0      0      0      0      0         0
%i    0    0    0    0      0      0      0      0         0
/* FINAL ORBIT COMBINATION FROM WEIGHTED AVERAGE OF:        
/* cod emr esa gfz grg jpl mit ngs sio                      
/* REFERENCED TO IGS TIME (IGST) AND TO WEIGHTED MEAN POLE: 
/* PCV:IGS08_1633 OL/AL:FES2004  NONE     Y  ORB:CMB CLK:CMB
*  2011  4 19  0  0  0.00000000
PG01  18897.608482    540.082488  18599.993574 999999.999999
PG02 -20204.170445  13653.480630   9952.956923    331.614342 10  6 10 138       
PG03  10622.069869 -21535.041979  10581.481322    703.817855  6  6  8 102       
PG04 -26066.529446   5690.754614  -2144.404088     92.080228 10  8  8 124       
PG05  -9170.910724  12402.572851  21597.496384   -146.772973  8  6  7 127       
PG06  14017.555859 -17687.638656  13988.386834    665.344726  4  6  8  92       
PG07 -18160.930828  -7643.617342  17911.142464      8.526717  7  9  8 126       
PG08 -24863.533262  -1743.091125   9960.655703      7.739279  9 12 11 147       
PG09  -1662.496074  15731.012804 -21885.854470     74.644942 11  8  9  95       
PG10 -19966.306302  -2669.040290  17279.950480    -71.937668  8  7  5 146       
PG11   1413.104409 -18700.621510 -19015.609009   -143.787452 10  9  7 120       
PG12   7907.258536  21296.216039 -13880.446566    -10.751195  7  7  9 124       
PG13  -7437.068376 -16822.264757  18993.386772    274.569565  7  8  7 141       
PG14  15443.790264  -1609.671516 -21371.051917    144.747500 11 11  9 153       
PG15  -3344.242493  25989.512413  -3745.773741   -134.254365  8  9 12 142       
PG16  10785.226508 -10284.746751  22014.450981   -166.120535  4  8  5 125       
PG17 -15718.539829   1031.788760 -21217.872782    184.367475  9 12  9 132       
PG18  20934.265804  15783.218184  -5038.930726    132.574240  8 11  9 115       
PG19   8056.503296 -25094.909831   -801.048176   -131.854348  7  9  9 134       
PG20 -11560.841193 -21369.377545 -10953.337549     48.966225 10  8 12 134       
PG21  19912.905427   7432.970048  16694.883464   -138.433980  8  7  9 102       
PG22  21304.285361   6298.557431 -14465.419095    149.981330  9 10  8 147       
PG23   -439.091670 -24532.625495   9712.295073    312.373050  8  9  8 130       
PG24  -1678.490424 -15414.883803 -21493.947314    382.771536 12  9  9 126       
PG25  18117.873502  19310.049473  -2238.715285     -1.145931  7  8  9 126       
PG26 -12130.627914  22220.743409   6691.258840     -6.431211  8  8 11 133       
PG27  -8130.573747  15978.528126 -18828.077498    256.815450  8  8  8 137       
PG28 -21129.294807 -10700.161394 -11760.098951     32.285342  9 11  8 136       
PG29   6233.903813  19867.655236  16593.397253    200.890975  7  6 10 146       
PG30  16674.979584  -3797.749816  19921.869540    337.951533  5 10  6 106       
PG31  25601.695949  -7478.761922    753.187282     68.421925 11  9  9 119       
PG32  -3066.032634 -20913.712764 -16044.702551   -237.731424 10  6 10 113       
*  2011  4 19  0 15  0.00000000
PG01  20323.873127   2015.074723  16943.695657 999999.999999
PG02 -21256.682427  13666.069511   7356.634381    331.616286 10  5 10 131       
PG03  10814.316143 -20093.153637  12909.587132    703.822136  5  6  8  99       
PG04 -25792.670155   5304.547165  -4897.456134     92.089434 10  8  8 103       
PG05 -11012.159990  10741.513227  21636.364294   -146.778036  8  6  7 128       
PG06  13980.827766 -15966.105116  15996.005706    665.248247  4  6  7 110       
PG07 -16160.276377  -8369.006832  19421.300551      8.527535  7  9  7 133       
PG08 -23657.958257  -2116.364966  12462.333308      7.738799  8 12 11 141       
PG09  -3889.169055  16438.558237 -21045.204881     74.646748 11  7  9 117       
PG10 -21223.761414  -4102.856926  15458.668397    -71.940278  7  7  4 147       
PG11   3297.835010 -19620.184268 -17762.674265   -143.790348  9  9  6 114       
PG12   6564.486822  20236.514832 -15985.466097    -10.748802  7  8  8 108       
PG13  -6724.160208 -18801.906081  17338.804890    274.568261  6  8  7 144       
PG14  14808.862344    812.205909 -21868.343958    144.749662 11 11  9 142       
PG15  -3688.839381  26195.084462   -918.770215   -134.251739  8  8 12 129       
PG16  12571.688860  -8540.084202  21838.175938   -166.123078  3  8  4 117       
PG17 -15160.120412  -1387.250935 -21617.661213    184.367339  9 12  8 136       
PG18  21055.538296  16312.061047  -2301.058198    132.575926  8 11  9 132       
PG19   8311.983932 -24939.466484   2069.081246   -131.857944  7  9  8 139       
PG20 -10344.651362 -20688.737318 -13258.522826     48.966095 10  7 11 126       
PG21  18122.886978   8143.730463  18306.875914   -138.436189  7  7  8 107       
PG22  22254.838423   7561.968141 -12300.923863    149.980503  9 10  8 152       
PG23     23.631681 -25419.309673   7052.354154    312.370577  7  8  7 128       
PG24    711.497095 -15983.165655 -21105.430230    382.774082 11  9  8 140       
PG25  17646.010421  19215.911996  -5058.215133     -1.145811  7  8  9  82       
PG26 -12040.996389  21199.423731   9418.433682     -6.440746  8  7 10 128       
PG27 -10234.998605  16605.122949 -17219.067574    256.817532  8  7  7 140       
PG28 -21895.910252 -11720.099896  -9248.283751     32.287531  8 11  9 149       
PG29   5622.587561  21537.795906  14602.153973    200.893677  7  6 10 143       
PG30  18352.503551  -2238.017114  18672.193654    337.954189  5 10  6 111       
PG31  25560.405887  -7272.216429  -2125.926164     68.426624  9  9  9 127       
PG32  -1616.505071 -19567.147050 -17790.158932   -237.738035 10  5  9 131       
*  2011  4 19  0 30  0.00000000
PG01  21666.693429   3281.945953  14995.042779 999999.999999
PG02 -22026.739139  13615.244932   4630.218708    331.618577 10  5 10 112       
PG03  11064.937614 -18406.867057  15006.694473    703.826978  5  6  7  98       
PG04 -25254.961927   4798.666799  -7568.316558     92.099144  9  8  8 101       
PG05 -12922.094710   9187.886823  21302.420501   -146.783352  8  6  6 128       
PG06  14003.664861 -14037.697998  17728.833050    665.151922  3  6  6 109       
PG07 -14058.486193  -9256.726434  20599.330298      8.528725  6  9  7 130       
PG08 -22217.141665  -2637.254159  14755.750856      7.739609  7 11 11 146       
PG09  -5970.152262  17229.900701 -19859.267894     74.647872 11  7  8 118       
PG10 -22382.034808  -5325.012816  13371.789448    -71.940612  6  7  4 153       
PG11   5020.540748 -20527.378202 -16207.871833   -143.793187  9  9  6 121       
PG12   4993.734793  19108.672593 -17816.952623    -10.746106  7  8  8 116       
PG13  -6172.243218 -20617.393536  15381.955055    274.566920  5  7  7 142       
PG14  14301.130161   3298.476199 -21983.496850    144.751951 11 10  8 159       
PG15  -3977.891046  26098.928981   1924.210200   -134.249159  8  7 11 136       
PG16  14417.636737  -6924.512420  21288.075117   -166.125649  3  8  3 116       
PG17 -14723.255656  -3853.464118 -21640.405809    184.367544  8 11  8 138       
PG18  20967.429745  16633.254910    475.682516    132.577811  7 10  8 111       
PG19   8497.203129 -24481.122825   4902.823321   -131.861397  6  9  8 138       
PG20  -8901.430977 -19919.430416 -15338.114749     48.966608 10  6 11 136       
PG21  16217.064743   8999.088004  19619.489935   -138.438330  6  6  8  99       
PG22  23068.299093   8611.224389  -9923.963953    149.979725  9 10  8 142       
PG23    388.105324 -26022.633571   4268.535587    312.368331  7  7  7 128       
PG24   3010.942541 -16650.678478 -20350.628998    382.777797 11  9  8 128       
PG25  16922.970537  18952.377852  -7790.800751     -1.145768  7  7  8  37       
PG26 -11939.694796  19873.456654  11975.476120     -6.450390  7  7 10 132       
PG27 -12111.672767  17260.520279 -15294.903117    256.819865  8  7  7 138       
PG28 -22495.024659 -12497.436498  -6576.184960     32.289419  8 10  9 141       
PG29   5145.355168  23003.584520  12361.350208    200.896395  7  6 10 140       
PG30  19975.241683   -864.978886  17090.720450    337.955600  5 10  6 105       
PG31  25228.355805  -6948.506016  -4968.836485     68.431319  9 10  8 130       
PG32     34.484260 -18168.927959 -19227.189687   -237.744665  9  4  9 124       
*  2011  4 19  0 45  0.00000000
PG01  22881.797267   4338.239564  12788.115599 999999.999999
PG02 -22514.148151  13464.156802   1821.793655    331.620402  9  5  9 133       
PG03  11400.188182 -16507.901958  16834.774083    703.831633  5  6  7  98       
PG04 -24478.263964   4146.518131 -10112.348835     92.108262  8  8  8  97       
PG05 -14860.302445   7768.322343  20601.734688   -146.788559  9  6  6 136       
PG06  14111.295168 -11937.409415  19157.893110    665.055438  4  5  5  95       
PG07 -11903.387206 -10305.308391  21424.560922      8.529796  5  8  6 123       
PG08 -20578.919067  -3327.607833  16801.977219      7.740505  6 11 11 136       
PG09  -7871.009133  18073.235418 -18346.590940     74.650388 10  6  8 108       
PG10 -23399.884656  -6335.845712  11056.058491    -71.941483  6  7  4 143       
PG11   6562.907398 -21386.633523 -14376.420776   -143.795900  8  9  6 114       
PG12   3208.922483  17955.794957 -19343.179595    -10.743646  7  9  7 120       
PG13  -5764.222686 -22225.117778  13157.176599    274.565764  5  6  7 141       
PG14  13932.716577   5798.881666 -21714.901172    144.754250 11 10  8 146       
PG15  -4247.516571  25697.424532   4733.736133   -134.246702  8  6 11 140       
PG16  16281.266926  -5464.119628  20374.411894   -166.128110  4  8  3 123       
PG17 -14417.149380  -6317.934983 -21286.396242    184.367294  8 11  8 136       
PG18  20646.804269  16772.854089   3244.450525    132.579406  7 10  8 113       
PG19   8649.616788 -23719.410799   7650.385454   -131.865079  6  9  7 137       
PG20  -7240.639983 -19100.809844 -17156.985094     48.966519  9  6 10 131       
PG21  14237.039964  10000.903025  20610.610698   -138.440716  5  6  7  99       
PG22  23707.261518   9453.487686  -7375.952803    149.979263  9 10  8 130       
PG23    687.983899 -26323.545904   1409.683569    312.365866  6  7  7 122       
PG24   5178.208800 -17393.465410 -19241.922954    382.780033 10  8  8 130       
PG25  15938.299681  18556.597486 -10389.536053     -1.145683  7  7  8  92       
PG26 -11865.982997  18260.446390  14315.186729     -6.460065  7  7  9 130       
PG27 -13733.877023  17904.915402 -13091.745475    256.823408  8  6  7 129       
PG28 -22890.542172 -13047.851390  -3790.849351     32.292102  8 10  9 141       
PG29   4779.09635
  2 件のコメント
gblmtc
gblmtc 2017 年 12 月 1 日
Thank you! this is the file I was talking about and I have to extract just the lines which start with PG10.

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

採用された回答

dpb
dpb 2017 年 12 月 1 日
編集済み: dpb 2017 年 12 月 2 日
fmt=['PG10 ' repmat('%f ',1,8)];
fid=fopen('sp3data.txt');
PG10=[];
while ~feof(fid)
PG10=[PG10; cell2mat(textscan(fid,fmt,'collectoutput',1))];
end
fid=fclose(fid);
is the "quick-n-dirty" solution. It simply concatenates the next set of values onto the preceding with dynamic reallocation. Presuming there aren't a zillion PG10 records in the file, this will be quick-enough.
If there are so many that performance is slow, preallocate the array as
PG10=zeros(AVERYBIGNUMBER,8);
and populate it by keeping a counter
i=0; % initialize counter
while ~feof(fid)
i=i+1; % increment
PG10(i,:)=cell2mat(textscan(fid,fmt,'collectoutput',1));
end
fid=fclose(fid);
ADDENDUM
Per the note in comments, the above won't work as is...
fmt=['PG10 ' repmat('%f ',1,8)];
fid=fopen('sp3data.txt');
PG10=[];
while ~feof(fid)
l=fgetl(fid); % read a record
if strfind(l,'PG10')
PG10=[PG10; cell2mat(textscan(l,fmt,'collectoutput',1))];
end
end
fid=fclose(fid);
  7 件のコメント
gblmtc
gblmtc 2017 年 12 月 4 日
Hi dpd! It actually worked. I tried now again and I have the PG10 with the lines I need. Today I meet my teacher and ask him if it's all ok. Thanks for your help!

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

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by