Read text data and create array?
Mostrar comentarios más antiguos
I have a .txt file with ISS orbital parameters that I'm looking to import into Matlab and use to plot things like satellite position, for example.
I have successfully pulled the data from the website and printed to the attached .txt file but when I use readtable(), Matlab generates a 212x1 matrix instead of splitting the columns and creating a full array. Unfortunately, the format from the website hosting the orbit data features an unequal number of delimiters as well.
Any help and/or guidance on how to read this data, split it into columns, and create variables from it would be much appreciated. I do not need the string data (i.e. "ISS (ZARYA) ") from the top of each two row data set. Thanks.
6 comentarios
dpb
el 28 de Mzo. de 2020
Is there description of the data file content so know what it is are looking at? What, for instance is the interpretation of the two fields containing "00000-0 -30560-5" in first record?
You'll have to read each set of three individually; there is no prebuilt function to handle such specific file formats automagically.
You might see if an online search will locate someobody has already written a script for such files; sometimes you can be amazed at what is already out there.
David Hamblin
el 28 de Mzo. de 2020
Walter Roberson
el 28 de Mzo. de 2020
This is a case where it would probably be easiest to loop doing fgetl() and indexing into the character vectors to extract parts, and converting the parts to numeric as needed.
There are also approaches based upon using regexp() and a bunch of named tokens and the 'names' option. That would give you a struct array of character vectors that you would still need to convert to numeric.
dpb
el 28 de Mzo. de 2020
Ah! Since are fixed width fields, the fixedWidthImportOptions object may be of help here...how big are the files? If one could load into memory readily as string array, then every third record is a given record type that could be parsed and then the pieces put back together. I've not had occasion to do such, but don't see why wouldn't be pretty straightforward to do so.
dpb
el 29 de Mzo. de 2020
WRT to the above comment and the table...how you want to name stuff? For example, there are multiple pieces of data buried in some of the variables like the Satellite Number and Classification are run together in one string but are separate fields--you want/need both of the composite?
Similar with the Designator excepting it has three composite pieces buried in it.
And, continues with the epoch year/day that are also run together.
Need to define what pieces you need as the individual variables or what you want to leave as encoded and deal with separating out the pieces on an as-needed basis.
You make a list of wanted variables and I'll see about encoding...since the guv now has us on lockdown, too, guess will not push the issue too hard.
David Hamblin
el 30 de Mzo. de 2020
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

