필터 지우기
필터 지우기

how to find a specific value from a textfile(3000 lines), when the value keeps on changing its location in the file

조회 수: 1 (최근 30일)
In my code, I have to download weather data every hour from the website ( http://api.met.no/weatherapi/locationforecast/1.9/?lat=52.37;lon=4.89;msl=1) I am able to do so but now i need to find the value for "cloudiness" for the time period 24 hours after it was downloaded. I just need numerical value of cloudiness. I tried getting that data by importing data from that specific cell, but the value keeps on changing its value location. So I need to update the cell location for every time I run my code.How should I get the exact numerical value.
For example: I want the cloudiness for the date "from="2015-03-12T11:00:00Z" to="2015-03-12T11:00:00Z"
The code goes like this:
<time datatype="forecast" from="2015-03-12T11:00:00Z" to="2015-03-12T11:00:00Z">
<location altitude="1" latitude="53.0500" longitude="4.8000">
<temperature id="TTT" unit="celsius" value="8.3"/>
<windDirection id="dd" deg="138.0" name="SE"/>
<windSpeed id="ff" mps="4.5" beaufort="3" name="Lett bris"/>
<humidity value="62.9" unit="percent"/>
<pressure id="pr" unit="hPa" value="1030.9"/>
*<cloudiness id="NN" percent="0.0"/>*
<fog id="FOG" percent="0.0"/>
<lowClouds id="LOW" percent="0.0"/>
<mediumClouds id="MEDIUM" percent="0.0"/>
<highClouds id="HIGH" percent="0.0"/>
<dewpointTemperature id="TD" unit="celsius" value="1.6"/>
</location>
</time>
<time datatype="forecast" from="2015-03-12T10:00:00Z" to="2015-03-12T11:00:00Z">
<location altitude="1" latitude="53.0500" longitude="4.8000">
<precipitation unit="mm" value="0.0" minvalue="0.0" maxvalue="0.0"/>
<symbol id="Sun" number="1"/>
</location>
</time>
<time datatype="forecast" from="2015-03-12T09:00:00Z" to="2015-03-12T11:00:00Z">
<location altitude="1" latitude="53.0500" longitude="4.8000">
<precipitation unit="mm" value="0.0" minvalue="0.0" maxvalue="0.0"/>
<symbol id="Sun" number="1"/>
</location>
</time>
<time datatype="forecast" from="2015-03-12T08:00:00Z" to="2015-03-12T11:00:00Z">
<location altitude="1" latitude="53.0500" longitude="4.8000">
<precipitation unit="mm" value="0.0" minvalue="0.0" maxvalue="0.0"/>
<symbol id="Sun" number="1"/>
</location>
</time>
<time datatype="forecast" from="2015-03-12T05:00:00Z" to="2015-03-12T11:00:00Z">
<location altitude="1" latitude="53.0500" longitude="4.8000">
<precipitation unit="mm" value="0.0" minvalue="0.0" maxvalue="0.0"/>
<symbol id="LightCloud" number="2"/>
</location>
</time>
This is one basic data in the file. Now i want to get numerical data (for cloudiness) in the line 10.
What will be the best way to read the particular data?

채택된 답변

Guillaume
Guillaume 2015년 3월 11일
Since your document is an xml file, the most reliable way would be to use xml parsing and navigate the dom to find the information of interest:
xdom = xmlread('http://api.met.no/weatherapi/locationforecast/1.9/?lat=52.37;lon=4.89;msl=1');
cloudtags = xdom.getElementsByTagName('cloudiness');
cloudiness = cell(cloudtags.getLength, 3);
for item = 1 : cloudtags.getLength
cloudtag = cloudtags.item(item - 1);
cloudiness{item, 1} = str2double(cloudtag.getAttribute('percent'));
timetag = cloudtag.getParentNode.getParentNode;
cloudiness{item, 2} = char(timetag.getAttribute('from'));
cloudiness{item, 3} = char(timetag.getAttribute('to'));
end
cloudiness
  댓글 수: 4

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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