Read text data and create array?
이전 댓글 표시
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
dpb
2020년 3월 28일
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
2020년 3월 28일
Walter Roberson
2020년 3월 28일
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
2020년 3월 28일
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
2020년 3월 29일
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
2020년 3월 30일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

