How to select a specific line from text file

조회 수: 14 (최근 30일)
Ebtesam Farid
Ebtesam Farid 2020년 11월 21일
댓글: Ameer Hamza 2020년 11월 21일
please, I have a text file of Radiosonde data, and I want to select a specific value from the first coulmn of the data.
I tried textscan function, but by using specific number of the header, it removes all the wanted headerlines and still give me all the rest of data.
this is a sample of my data, I want to select the first temperature record (here is -34.9) only from the whole text.
<HTML>
<TITLE>University of Wyoming - Radiosonde Data</TITLE>
<BODY BGCOLOR="white">
<H2>71081 YUX Hall Beach Observations at 12Z 13 Dec 2016</H2>
<PRE>
-----------------------------------------------------------------------------
PRES HGHT TEMP DWPT RELH MIXR DRCT SKNT THTA THTE THTV
hPa m C C % g/kg deg knot K K K
-----------------------------------------------------------------------------
1008.0 6 -31.7 -34.9 73 0.20 300 8 240.9 241.5 240.9
1000.0 61 -28.3 -31.4 75 0.28 310 16 244.8 245.6 244.9
995.0 97 -25.7 -29.5 70 0.34 314 16 247.8 248.8 247.9
967.0 305 -22.6 -29.8 52 0.34 340 16 253.0 253.9 253.0
961.0 350 -21.9 -29.9 48 0.34 336 15 254.1 255.1 254.2
927.6 610 -21.3 -31.2 41 0.31 315 12 257.3 258.2 257.3
925.0 631 -21.3 -31.3 40 0.30 295 11 257.5 258.4 257.6
901.0 825 -21.9 -29.9 48 0.36 312 10 258.9 259.9 258.9
any advice, please.
Thanks

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 21일
If the file have fixed number of header lines, then try this
f = fopen('data.txt');
data = textscan(f, '%f', 'HeaderLines', 9);
fclose(f);
val = data{1}(3)
  댓글 수: 2
Ebtesam Farid
Ebtesam Farid 2020년 11월 21일
it works well, thanks so much
Ameer Hamza
Ameer Hamza 2020년 11월 21일
I am glad to be of help!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by