Scanning a text file for bits and pieces of information
이전 댓글 표시
Hi.
I'm new to matlab and I'm a bit stuck in where to begin with coding a program to open a text file, read specific strings and extract information from specific strings. Here's my general outline and an example of the text format I'm trying to read.
Example format:(wanted information has asterisks on either side of it)
<solution solution_id="telemetry" name="SITE_FRAME" add_date="2004-01-26T12:04:23Z" index1="1">
<reference_frame name="SITE_FRAME" index1=" *0* "/>
<offset x=" *-0.0* " y=" *0.0* " z=" *0.0* "/>
<orientation s="1.0" v1="0.0" v2="0.0" v3="0.0"/>
</solution>
<alias>
<old index1="0" index2="0" index3="1" index4="59"/>
<new index1="1"/>
</alias>
<solution solution_id="telemetry" name="SITE_FRAME" add_date="2004-01-26T12:04:25Z" index1="2">
<reference_frame name="SITE_FRAME" index1=" *1* "/>
<offset x=" *-0.0* " y=" *0.0* " z=" *0.0* "/>
<orientation s="1.0" v1="0.0" v2="0.0" v3="0.0"/>
</solution>
<alias>
<old index1="1" index2="0" index3="0" index4="13"/>
<new index1="2"/>
Outline:
Open file 'mer_site' (that's the file that contains this format of information)
Look for instances of * information
ie the parts that say 'name=SITE_FRAME" index1="*"/>'
export the * information into a vector (total size [1x158])
Look for instances of * information
ie the parts that say '<offset x="*" y="*" z="*"/>'
export the * information into a vector (total size [3x158])
Close File
So far, all I know is that I need
fid=fopen('mer_site')
something with textscan
something about putting the results from textscan into a cell
closing the file
I'm not sure which arguments I need for textscan because the information is mixed.
I'd be super grateful if anyone could help with this!!!
댓글 수: 9
Walter Roberson
2015년 7월 20일
Would you be able to use an xml parser on this?
Elena H.
2015년 7월 20일
per isakson
2015년 7월 20일
편집: per isakson
2015년 7월 20일
You show an excerpt of a file and we guess that it is an xml-file. We are probably mistaken.
Elena H.
2015년 7월 20일
Walter Roberson
2015년 7월 20일
That file does not appear to be in Simple File Verification (SFV) format. Perhaps it has something to do with State Fusion Vector ?
Elena H.
2015년 7월 20일
per isakson
2015년 7월 20일
I found an "issue" with mer1_master.
<solution solution_id="telemetry" name="SITE_FRAME" add_date="2013-12-03T17:01:12Z" index1="182">
<reference_frame name="SITE_FRAME" index1="181"/>
....
<solution add_date="2014-02-16T19:02:11Z" index1="183" name="SITE_FRAME" solution_id="telemetry">
<reference_frame index1="182" name="SITE_FRAME"/>
....
The order of the "items" changes after index, 183. I guess that is not significant with an xml-file.
Walter Roberson
2015년 7월 20일
The directory above says that the files are indeed XML files.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!