Import data from file

8 次查看(过去 30 天)
Mirko Rizzi
Mirko Rizzi 2023-10-14
编辑: dpb 2023-10-14
Hello everyone,
i have this txt file, and i want to import it inside matlab, as a matrix, in order to extract the data i need.
this should be the same every time i import this kind of text file.
i need that alla the words have to be in a same column and also the numbers, in order to extract them easily and use for calculation
Thank you all!
  1 个评论
dpb
dpb 2023-10-14
Things like that will just have to read line by line and parse -- if it is the same format of titles but differing bodies, then taking the one and using it to create a template would probably be about as good a way as any; it's too irregular to do much else with.
I'd be looking to see if there's any possible way to get the output in a more useful format first...maybe there is an option to create a file for import into something else already???
If not, enjoy...it will be tedious, but not terribly difficult to split lines and extractAfter, but the oddball pieces between sections, etc., will be one-of-a-kind to handle, hence the idea of a template.
Now, if descriptions either change names or there are different fields between files, it becomes a whole lot more of a challenge.

请先登录,再进行评论。

回答(2 个)

Star Strider
Star Strider 2023-10-14
This segments some of the file information into 31 individual cells of character vectors . I have no idea what you want from this file (and I do not understand the information in it), so I leave aubsequently parsing it to you.
type('Moon_ephemerides.txt') % Overview
******************************************************************************* Revised: July 31, 2013 Moon / (Earth) 301 GEOPHYSICAL DATA (updated 2018-Aug-15): Vol. mean radius, km = 1737.53+-0.03 Mass, x10^22 kg = 7.349 Radius (gravity), km = 1738.0 Surface emissivity = 0.92 Radius (IAU), km = 1737.4 GM, km^3/s^2 = 4902.800066 Density, g/cm^3 = 3.3437 GM 1-sigma, km^3/s^2 = +-0.0001 V(1,0) = +0.21 Surface accel., m/s^2 = 1.62 Earth/Moon mass ratio = 81.3005690769 Farside crust. thick. = ~80 - 90 km Mean crustal density = 2.97+-.07 g/cm^3 Nearside crust. thick.= 58+-8 km Heat flow, Apollo 15 = 3.1+-.6 mW/m^2 Mean angular diameter = 31'05.2" Heat flow, Apollo 17 = 2.2+-.5 mW/m^2 Sid. rot. rate, rad/s = 0.0000026617 Geometric Albedo = 0.12 Mean solar day = 29.5306 d Obliquity to orbit = 6.67 deg Orbit period = 27.321582 d Semi-major axis, a = 384400 km Eccentricity = 0.05490 Mean motion, rad/s = 2.6616995x10^-6 Inclination = 5.145 deg Apsidal period = 3231.50 d Nodal period = 6798.38 d Perihelion Aphelion Mean Solar Constant (W/m^2) 1414+-7 1323+-7 1368+-7 Maximum Planetary IR (W/m^2) 1314 1226 1268 Minimum Planetary IR (W/m^2) 5.2 5.2 5.2 ******************************************************************************** ******************************************************************************* Ephemeris / WWW_USER Sat Oct 14 02:27:45 2023 Pasadena, USA / Horizons ******************************************************************************* Target body name: Moon (301) {source: DE441} Center body name: Sun (10) {source: DE441} Center-site name: BODY CENTER ******************************************************************************* Start time : A.D. 2023-Oct-14 00:00:00.0000 TDB Stop time : A.D. 2023-Nov-13 00:00:00.0000 TDB Step-size : 1440 minutes ******************************************************************************* Center geodetic : 0.0, 0.0, 0.0 {E-lon(deg),Lat(deg),Alt(km)} Center cylindric: 0.0, 0.0, 0.0 {E-lon(deg),Dxy(km),Dz(km)} Center radii : 696000.0, 696000.0, 696000.0 km {Equator_a, b, pole_c} Keplerian GM : 1.3271244494407951E+11 km^3/s^2 Output units : KM-S, deg, Julian Day Number (Tp) Calendar mode : Mixed Julian/Gregorian Output type : GEOMETRIC osculating elements Output format : 10 Reference frame : Ecliptic of J2000.0 ******************************************************************************* JDTDB EC QR IN OM W Tp N MA TA A AD PR ******************************************************************************* $$SOE 2460231.500000000 = A.D. 2023-Oct-14 00:00:00.0000 TDB EC= 6.708238701611562E-02 QR= 1.305422290480587E+08 IN= 1.779850905168868E-01 OM= 2.006298096125623E+02 W = 3.427139011385083E+02 Tp= 2460379.212703947444 N = 1.261005148995971E-05 MA= 1.990657610641118E+02 TA= 1.967402583773381E+02 A = 1.399290004082212E+08 AD= 1.493157717683837E+08 PR= 2.854865424511841E+07 2460232.500000000 = A.D. 2023-Oct-15 00:00:00.0000 TDB EC= 6.601916602469800E-02 QR= 1.305766289994362E+08 IN= 1.827652469764901E-01 OM= 2.006242741313951E+02 W = 3.487366824700003E+02 Tp= 2460385.310246856418 N = 1.262662333055120E-05 MA= 1.932931502115751E+02 TA= 1.916835181278043E+02 A = 1.398065401874072E+08 AD= 1.490364513753783E+08 PR= 2.851118549873498E+07 2460233.500000000 = A.D. 2023-Oct-16 00:00:00.0000 TDB EC= 6.276307788208889E-02 QR= 1.312776673248514E+08 IN= 1.785855330328728E-01 OM= 2.005990902804313E+02 W = 3.546542064992378E+02 Tp= 2460391.937474731356 N = 1.259117512924981E-05 MA= 1.876394311446943E+02 TA= 1.867525148647719E+02 A = 1.400688174215311E+08 AD= 1.488599675182107E+08 PR= 2.859145364150367E+07 2460234.500000000 = A.D. 2023-Oct-17 00:00:00.0000 TDB EC= 5.722723002437977E-02 QR= 1.326753544115309E+08 IN= 1.652749847563405E-01 OM= 2.004425524885100E+02 W = 9.545353225884807E-01 Tp= 2460399.501370432787 N = 1.250269446990991E-05 MA= 1.817601072504066E+02 TA= 1.815721600361922E+02 A = 1.407288783011434E+08 AD= 1.487824021907559E+08 PR= 2.879379327923336E+07 2460235.500000000 = A.D. 2023-Oct-18 00:00:00.0000 TDB EC= 4.947437842128170E-02 QR= 1.347752848659855E+08 IN= 1.431977943660921E-01 OM= 1.999732353794056E+02 W = 8.394312367696479E+00 Tp= 2460071.555237017106 N = 1.236257136372924E-05 MA= 1.751136910923617E+02 TA= 1.755685063628673E+02 A = 1.417902703581399E+08 AD= 1.488052558502944E+08 PR= 2.912015546023138E+07 2460236.500000000 = A.D. 2023-Oct-19 00:00:00.0000 TDB EC= 3.978197475771175E-02 QR= 1.375455227227727E+08 IN= 1.133023026544428E-01 OM= 1.987909703299211E+02 W = 1.852409154349730E+01 Tp= 2460078.136563440319 N = 1.217484810928043E-05 MA= 1.665835879258115E+02 TA= 1.675923841548222E+02 A = 1.432440540658111E+08 AD= 1.489425854088495E+08 PR= 2.956915739470996E+07 2460237.500000000 = A.D. 2023-Oct-20 00:00:00.0000 TDB EC= 2.885819720025339E-02 QR= 1.408789521073696E+08 IN= 7.718258775216268E-02 OM= 1.956691209662658E+02 W = 3.555083271621370E+01 Tp= 2460089.052708767820 N = 1.194629573684605E-05 MA= 1.532213489427855E+02 TA= 1.546645669965221E+02 A = 1.450652744030003E+08 AD= 1.492515966986309E+08 PR= 3.013486422319593E+07 2460238.500000000 = A.D. 2023-Oct-21 00:00:00.0000 TDB EC= 1.885780966020215E-02 QR= 1.444326214323524E+08 IN= 3.764198130057611E-02 OM= 1.839761607138229E+02 W = 7.547250815293630E+01 Tp= 2460114.018933169544 N = 1.168633802212937E-05 MA= 1.256884840224725E+02 TA= 1.274195221169724E+02 A = 1.472086542138517E+08 AD= 1.499846869953511E+08 PR= 3.080520170803722E+07 2460239.500000000 = A.D. 2023-Oct-22 00:00:00.0000 TDB EC= 1.679944154819838E-02 QR= 1.470903150300190E+08 IN= 1.731923670520762E-02 OM= 8.699518220755257E+01 W = 2.261298694457259E+02 Tp= 2460165.548352496698 N = 1.140684434122315E-05 MA= 7.288314611146487E+01 TA= 7.473406861288636E+01 A = 1.496035714845758E+08 AD= 1.521168279391327E+08 PR= 3.155999935047746E+07 2460240.500000000 = A.D. 2023-Oct-23 00:00:00.0000 TDB EC= 2.617176665053490E-02 QR= 1.481671972232650E+08 IN= 5.408793041406301E-02 OM= 4.422304912842680E+01 W = 3.073340248247179E+02 Tp= 2460203.544587354176 N = 1.112176978637470E-05 MA= 3.551122873218893E+01 TA= 3.730058580043897E+01 A = 1.521492108661161E+08 AD= 1.561312245089671E+08 PR= 3.236894908947286E+07 2460241.500000000 = A.D. 2023-Oct-24 00:00:00.0000 TDB EC= 3.936351480995399E-02 QR= 1.486221158934922E+08 IN= 9.335843868526483E-02 OM= 3.790256139149359E+01 W = 3.313790953706253E+02 Tp= 2460221.183747315314 N = 1.084655726339264E-05 MA= 1.903922479764701E+01 TA= 2.058213714026650E+01 A = 1.547121290777227E+08 AD= 1.608021422619531E+08 PR= 3.319025486686063E+07 2460242.500000000 = A.D. 2023-Oct-25 00:00:00.0000 TDB EC= 5.255046531528682E-02 QR= 1.488725977415121E+08 IN= 1.276133096485758E-01 OM= 3.586866295109687E+01 W = 3.438639780402642E+02 Tp= 2460231.551852338947 N = 1.059718309014250E-05 MA= 1.002408698254394E+01 TA= 1.114446145292002E+01 A = 1.571298441674291E+08 AD= 1.653870905933460E+08 PR= 3.397129189311374E+07 2460243.500000000 = A.D. 2023-Oct-26 00:00:00.0000 TDB EC= 6.418063300133904E-02 QR= 1.490050867959351E+08 IN= 1.541596999541305E-01 OM= 3.509074315698309E+01 W = 3.523586857920421E+02 Tp= 2460239.151364068966 N = 1.038878739266626E-05 MA= 3.903297477242836E+00 TA= 4.447323193897354E+00 A = 1.592241965175618E+08 AD= 1.694433062391886E+08 PR= 3.465274496368402E+07 2460244.500000000 = A.D. 2023-Oct-27 00:00:00.0000 TDB EC= 7.331257401594746E-02 QR= 1.490350032527461E+08 IN= 1.711812968511041E-01 OM= 3.481879811309954E+01 W = 3.591889183958457E+02 Tp= 2460245.557753238361 N = 1.023401244462685E-05 MA= 3.590647148328832E+02 TA= 3.589138152613431E+02 A = 1.608255373644305E+08 AD= 1.726160714761148E+08 PR= 3.517681866695503E+07 2460245.500000000 = A.D. 2023-Oct-28 00:00:00.0000 TDB EC= 7.936452888389114E-02 QR= 1.489616133955588E+08 IN= 1.777104925761780E-01 OM= 3.476280656849102E+01 W = 5.335824686517989E+00 Tp= 2460251.468163591810 N = 1.014141282801999E-05 MA= 3.547705872260368E+02 TA= 3.538513058114260E+02 A = 1.618030350437932E+08 AD= 1.746444566920275E+08 PR= 3.549801256540372E+07 2460246.500000000 = A.D. 2023-Oct-29 00:00:00.0000 TDB EC= 8.210644431017361E-02 QR= 1.487819204166362E+08 IN= 1.736874404939800E-01 OM= 3.476461114521153E+01 W = 1.134285167101905E+01 Tp= 2460257.274481790606 N = 1.011443664819253E-05 MA= 3.505843169146366E+02 TA= 3.488728354913133E+02 A = 1.620906035284471E+08 AD= 1.753992866402580E+08 PR= 3.559268919483841E+07 2460247.500000000 = A.D. 2023-Oct-30 00:00:00.0000 TDB EC= 8.165444522964820E-02 QR= 1.484940898843932E+08 IN= 1.598939304003312E-01 OM= 3.469662313026230E+01 W = 1.761782215834916E+01 Tp= 2460263.261277067475 N = 1.015135221157388E-05 MA= 3.461761490558901E+02 TA= 3.436964822218505E+02 A = 1.616974014988582E+08 AD= 1.749007131133231E+08 PR= 3.546325578079663E+07 2460248.500000000 = A.D. 2023-Oct-31 00:00:00.0000 TDB EC= 7.842074693316992E-02 QR= 1.480965806652482E+08 IN= 1.377569024110247E-01 OM= 3.439788491985993E+01 W = 2.458851953616811E+01 Tp= 2460269.694703301415 N = 1.024613194404600E-05 MA= 3.412370540270196E+02 TA= 3.380538500565543E+02 A = 1.606986921335443E+08 AD= 1.733008036018403E+08 PR= 3.513521023991838E+07 2460249.500000000 = A.D. 2023-Nov-01 00:00:00.0000 TDB EC= 7.303254492721295E-02 QR= 1.475848318185796E+08 IN= 1.090911240879864E-01 OM= 3.356297085314788E+01 W = 3.287171616295392E+01 Tp= 2460276.877008254640 N = 1.038992949659119E-05 MA= 3.354239359648216E+02 TA= 3.316322394255093E+02 A = 1.592125279166257E+08 AD= 1.708402240146718E+08 PR= 3.464893579096102E+07 2460250.500000000 = A.D. 2023-Nov-02 00:00:00.0000 TDB EC= 6.625478265818779E-02 QR= 1.469462948640829E+08 IN= 7.588567857863730E-02 OM= 3.135409958611163E+01 W = 4.370809801287157E+01 Tp= 2460285.188382122666 N = 1.057263119134124E-05 MA= 3.283130185222715E+02 TA= 3.240276623662783E+02 A = 1.573730093980132E+08 AD= 1.677997239319435E+08 PR= 3.405018045979249E+07 2460251.500000000 = A.D. 2023-Nov-03 00:00:00.0000 TDB EC= 5.894660965514741E-02 QR= 1.461542224902364E+08 IN= 4.037691092317610E-02 OM= 2.395864793111844E+01 W = 6.143460529520777E+01 Tp= 2460295.108137063216 N = 1.078407259254720E-05 MA= 3.193683855220929E+02 TA= 3.147149980487482E+02 A = 1.553091716046819E+08 AD= 1.644641207191274E+08 PR= 3.338256460261531E+07 2460252.500000000 = A.D. 2023-Nov-04 00:00:00.0000 TDB EC= 5.205634300567468E-02 QR= 1.451616175189184E+08 IN= 1.164900256733101E-02 OM= 3.171195806975547E+02 W = 1.409089055918110E+02 Tp= 2460307.156794043258 N = 1.101474751730015E-05 MA= 3.079845400470027E+02 TA= 3.030930717031536E+02 A = 1.531331703607648E+08 AD= 1.611047232026112E+08 PR= 3.268345456258270E+07 2460253.500000000 = A.D. 2023-Nov-05 00:00:00.0000 TDB EC= 4.660732741246183E-02 QR= 1.439020568311468E+08 IN= 3.770349943293955E-02 OM= 2.395347442985162E+02 W = 2.338375647146518E+02 Tp= 2460321.615256632678 N = 1.125604109419011E-05 MA= 2.937564177582034E+02 TA= 2.887571597495227E+02 A = 1.509368185519950E+08 AD= 1.579715802728432E+08 PR= 3.198282566557231E+07 2460254.500000000 = A.D. 2023-Nov-06 00:00:00.0000 TDB EC= 4.354180509384522E-02 QR= 1.423147827812369E+08 IN= 7.215784691342055E-02 OM= 2.313669668186777E+02 W = 2.596403153104097E+02 Tp= 2460337.929993542377 N = 1.150012139884001E-05 MA= 2.771030833307690E+02 TA= 2.721245908283183E+02 A = 1.487935212842214E+08 AD= 1.552722597872059E+08 PR= 3.130401736770468E+07 2460255.500000000 = A.D. 2023-Nov-07 00:00:00.0000 TDB EC= 4.332077709368160E-02 QR= 1.404048406471955E+08 IN= 1.041711996546135E-01 OM= 2.289781055116957E+02 W = 2.802688195322502E+02 Tp= 2460354.371829860844 N = 1.173964188936667E-05 MA= 2.597138027555847E+02 TA= 2.548819129765170E+02 A = 1.467627155324397E+08 AD= 1.531205904176840E+08 PR= 3.066533062870296E+07 2460256.500000000 = A.D. 2023-Nov-08 00:00:00.0000 TDB EC= 4.558498941925003E-02 QR= 1.382897696325027E+08 IN= 1.320548916310563E-01 OM= 2.280546555081644E+02 W = 2.979245397128466E+02 Tp= 2460368.973626999650 N = 1.196738518064143E-05 MA= 2.437042852540920E+02 TA= 2.391414023753707E+02 A = 1.448947974407433E+08 AD= 1.514998252489840E+08 PR= 3.008175926202658E+07 2460257.500000000 = A.D. 2023-Nov-09 00:00:00.0000 TDB EC= 4.935605894954084E-02 QR= 1.361658520491941E+08 IN= 1.544956916469544E-01 OM= 2.276967955295855E+02 W = 3.123891296315447E+02 Tp= 2460380.885912804864 N = 1.217595326249575E-05 MA= 2.301977283064354E+02 TA= 2.260216250982519E+02 A = 1.432353862148757E+08 AD= 1.503049203805574E+08 PR= 2.956647354329688E+07 2460258.500000000 = A.D. 2023-Nov-10 00:00:00.0000 TDB EC= 5.353323474572830E-02 QR= 1.342358088072489E+08 IN= 1.702735934933402E-01 OM= 2.275915941146908E+02 W = 3.240344632619005E+02 Tp= 2460390.426400333643 N = 1.235759433507168E-05 MA= 2.191426902079060E+02 TA= 2.154642087826177E+02 A = 1.418283385483546E+08 AD= 1.494208682894603E+08 PR= 2.913188362060857E+07 2460259.500000000 = A.D. 2023-Nov-11 00:00:00.0000 TDB EC= 5.717671833116478E-02 QR= 1.326714704789879E+08 IN= 1.782789898253435E-01 OM= 2.275872929841714E+02 W = 3.335881371110871E+02 Tp= 2460398.364999666344 N = 1.250424835292356E-05 MA= 2.099748288939520E+02 TA= 2.068940667392902E+02 A = 1.407172192907180E+08 AD= 1.487629681024482E+08 PR= 2.879021512043385E+07 2460260.500000000 = A.D. 2023-Nov-12 00:00:00.0000 TDB EC= 5.955209083026299E-02 QR= 1.316110654327014E+08 IN= 1.776141301059707E-01 OM= 2.275795244954886E+02 W = 3.417808110554841E+02 Tp= 2460405.466541932430 N = 1.260787713862549E-05 MA= 2.020849617692589E+02 TA= 1.996858461488934E+02 A = 1.399450880260796E+08 AD= 1.482791106194578E+08 PR= 2.855357773888072E+07 2460261.500000000 = A.D. 2023-Nov-13 00:00:00.0000 TDB EC= 6.010399078992598E-02 QR= 1.311649404724876E+08 IN= 1.677445351467917E-01 OM= 2.274599635378678E+02 W = 3.492644199827430E+02 Tp= 2460412.376349963713 N = 1.266110225121013E-05 MA= 1.949534587429040E+02 TA= 1.932970601167444E+02 A = 1.395526092112295E+08 AD= 1.479402779499714E+08 PR= 2.843354337222824E+07 $$EOE ******************************************************************************* TIME Barycentric Dynamical Time ("TDB" or T_eph) output was requested. This continuous coordinate time is equivalent to the relativistic proper time of a clock at rest in a reference frame co-moving with the solar system barycenter but outside the system's gravity well. It is the independent variable in the solar system relativistic equations of motion. TDB runs at a uniform rate of one SI second per second and is independent of irregularities in Earth's rotation. CALENDAR SYSTEM Mixed calendar mode was active such that calendar dates after AD 1582-Oct-15 (if any) are in the modern Gregorian system. Dates prior to 1582-Oct-5 (if any) are in the Julian calendar system, which is automatically extended for dates prior to its adoption on 45-Jan-1 BC. The Julian calendar is useful for matching historical dates. The Gregorian calendar more accurately corresponds to the Earth's orbital motion and seasons. A "Gregorian-only" calendar mode is available if such physical events are the primary interest. REFERENCE FRAME AND COORDINATES Ecliptic at the standard reference epoch Reference epoch: J2000.0 X-Y plane: adopted Earth orbital plane at the reference epoch Note: IAU76 obliquity of 84381.448 arcseconds wrt ICRF X-Y plane X-axis : ICRF Z-axis : perpendicular to the X-Y plane in the directional (+ or -) sense of Earth's north pole at the reference epoch. Symbol meaning: JDTDB Julian Day Number, Barycentric Dynamical Time EC Eccentricity, e QR Periapsis distance, q (km) IN Inclination w.r.t X-Y plane, i (degrees) OM Longitude of Ascending Node, OMEGA, (degrees) W Argument of Perifocus, w (degrees) Tp Time of periapsis (Julian Day Number) N Mean motion, n (degrees/sec) MA Mean anomaly, M (degrees) TA True anomaly, nu (degrees) A Semi-major axis, a (km) AD Apoapsis distance (km) PR Sidereal orbit period (sec) ABERRATIONS AND CORRECTIONS Geometric osculating elements have NO corrections or aberrations applied. Computations by ... Solar System Dynamics Group, Horizons On-Line Ephemeris System 4800 Oak Grove Drive, Jet Propulsion Laboratory Pasadena, CA 91109 USA General site: https://ssd.jpl.nasa.gov/ Mailing list: https://ssd.jpl.nasa.gov/email_list.html System news : https://ssd.jpl.nasa.gov/horizons/news.html User Guide : https://ssd.jpl.nasa.gov/horizons/manual.html Connect : browser https://ssd.jpl.nasa.gov/horizons/app.html#/x API https://ssd-api.jpl.nasa.gov/doc/horizons.html command-line telnet ssd.jpl.nasa.gov 6775 e-mail/batch https://ssd.jpl.nasa.gov/ftp/ssd/hrzn_batch.txt scripts https://ssd.jpl.nasa.gov/ftp/ssd/SCRIPTS Author : Jon.D.Giorgini@jpl.nasa.gov *******************************************************************************
% MoonText = fileread('Moon_ephemerides.txt')
fidi = fopen('Moon_ephemerides.txt','rt');
for k = 1:53
L = fgetl(fidi);
end
L
L = '$$SOE'
k
k = 53
for k1 = (k+1):5:1E+5
for k2 = 1:5
Segment{ceil((k1-k)/5),k2} = fgetl(fidi);
EOE = strcmp(Segment{ceil((k1-k)/5),k2},'$$EOE');
if EOE
k1
LastIdx = ceil((k1-k)/5)-1
break
end
end
if EOE
break
end
end
k1 = 209
LastIdx = 31
Segment{1,:}
ans = '2460231.500000000 = A.D. 2023-Oct-14 00:00:00.0000 TDB '
ans = ' EC= 6.708238701611562E-02 QR= 1.305422290480587E+08 IN= 1.779850905168868E-01'
ans = ' OM= 2.006298096125623E+02 W = 3.427139011385083E+02 Tp= 2460379.212703947444'
ans = ' N = 1.261005148995971E-05 MA= 1.990657610641118E+02 TA= 1.967402583773381E+02'
ans = ' A = 1.399290004082212E+08 AD= 1.493157717683837E+08 PR= 2.854865424511841E+07'
Segment{2,:}
ans = '2460232.500000000 = A.D. 2023-Oct-15 00:00:00.0000 TDB '
ans = ' EC= 6.601916602469800E-02 QR= 1.305766289994362E+08 IN= 1.827652469764901E-01'
ans = ' OM= 2.006242741313951E+02 W = 3.487366824700003E+02 Tp= 2460385.310246856418'
ans = ' N = 1.262662333055120E-05 MA= 1.932931502115751E+02 TA= 1.916835181278043E+02'
ans = ' A = 1.398065401874072E+08 AD= 1.490364513753783E+08 PR= 2.851118549873498E+07'
Segment{LastIdx,:}
ans = '2460261.500000000 = A.D. 2023-Nov-13 00:00:00.0000 TDB '
ans = ' EC= 6.010399078992598E-02 QR= 1.311649404724876E+08 IN= 1.677445351467917E-01'
ans = ' OM= 2.274599635378678E+02 W = 3.492644199827430E+02 Tp= 2460412.376349963713'
ans = ' N = 1.266110225121013E-05 MA= 1.949534587429040E+02 TA= 1.932970601167444E+02'
ans = ' A = 1.395526092112295E+08 AD= 1.479402779499714E+08 PR= 2.843354337222824E+07'
.

dpb
dpb 2023-10-14
编辑:dpb 2023-10-14
If the need is just the timeseries data at the end and not the header stuff, then it gets easier...
d=dir('*.txt');
l=readlines(d.name); % bring in as string array
ix0=find(matches(l,'JDTDB')); % find the variables section start
ix1=find(matches(l,'$$SOE')); % find the beginning
ix2=find(matches(l,'$$EOE')); % find the end
VARS=split(strtrim(l(ix0+1:ix1-2))); % the variable names
VARS=reshape(VARS.',1,[]); % row vector in scanned order
l=l(ix1+1:ix2-1); % save time series section only
ix=contains(l,'= A.D.'); % find time records
t=str2double(extractBefore(l(ix),' =')); % retrieve Julian date
td=datetime(extractBetween(l(ix),'A.D. ',' TDB')); % retrieve calendar date
l(ix)=[]; % now remove time records
l=strtrim(l); % and leading blank
N=numel(l); % size of array
v=zeros(N,3); % place for values
for i=1:N % convert all records
ll=strrep(l(i),' =','1='); % embedded blank causes trouble parsing
v(i,:)=cell2mat(textscan(char(ll),'%*c%*c= %f %*c%*c= %f %*c%*c= %f'));
end
v=reshape(v.',numel(VARS),[]).'; % rearrange by variable by column
tData=[table(t) table(td) array2table(v)]; % and put altogether in a table
tData.Properties.VariableNames=[{'Julian','Date'} VARS]; % name variables
head(tData) % show off what we gots...
Julian Date EC QR IN OM W Tp N MA TA A AD PR __________ ___________ ________ __________ ________ ______ _______ __________ __________ ______ ______ __________ __________ __________ 2.4602e+06 14-Oct-2023 0.067082 1.3054e+08 0.17799 200.63 342.71 2.4604e+06 1.261e-05 199.07 196.74 1.3993e+08 1.4932e+08 2.8549e+07 2.4602e+06 15-Oct-2023 0.066019 1.3058e+08 0.18277 200.62 348.74 2.4604e+06 1.2627e-05 193.29 191.68 1.3981e+08 1.4904e+08 2.8511e+07 2.4602e+06 16-Oct-2023 0.062763 1.3128e+08 0.17859 200.6 354.65 2.4604e+06 1.2591e-05 187.64 186.75 1.4007e+08 1.4886e+08 2.8591e+07 2.4602e+06 17-Oct-2023 0.057227 1.3268e+08 0.16527 200.44 0.95454 2.4604e+06 1.2503e-05 181.76 181.57 1.4073e+08 1.4878e+08 2.8794e+07 2.4602e+06 18-Oct-2023 0.049474 1.3478e+08 0.1432 199.97 8.3943 2.4601e+06 1.2363e-05 175.11 175.57 1.4179e+08 1.4881e+08 2.912e+07 2.4602e+06 19-Oct-2023 0.039782 1.3755e+08 0.1133 198.79 18.524 2.4601e+06 1.2175e-05 166.58 167.59 1.4324e+08 1.4894e+08 2.9569e+07 2.4602e+06 20-Oct-2023 0.028858 1.4088e+08 0.077183 195.67 35.551 2.4601e+06 1.1946e-05 153.22 154.66 1.4507e+08 1.4925e+08 3.0135e+07 2.4602e+06 21-Oct-2023 0.018858 1.4443e+08 0.037642 183.98 75.473 2.4601e+06 1.1686e-05 125.69 127.42 1.4721e+08 1.4998e+08 3.0805e+07

类别

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