readmatrix not doing fixed width delimitation correctly

조회 수: 12 (최근 30일)
Richard Nash
Richard Nash 2022년 7월 13일
댓글: Richard Nash 2022년 7월 13일
I have a .txt file, a snippet of which is shown below - hopefully this preserves formattign adequatly, shout if not!
-----------------------------------------------------------------------------
PRES HGHT TEMP DWPT RELH MIXR DRCT SKNT THTA THTE THTV
hPa m C C % g/kg deg knot K K K
-----------------------------------------------------------------------------
1022.0 52 15.8 10.8 72 8.02 295 4 287.2 309.8 288.6
1014.0 118 17.4 10.4 63 7.86 305 10 289.4 311.8 290.8
1002.0 218 17.6 9.6 59 7.54 320 15 290.6 312.2 291.9
1000.0 235 17.6 10.6 64 8.08 320 15 290.8 313.9 292.2
992.0 303 17.1 10.1 63 7.85 325 14 290.9 313.4 292.2
I don't need anything above the first numerical line. When the data is fixed width - and as far as I can see from succesful imports into excel the correct width is 7.
So I do the following
FILENAME = 'sonde.txt';
opts = detectImportOptions('sonde.txt');
opts.DataLines = [5 Inf];
opts.VariableWidths = 7;
sondeData = readmatrix(FILENAME,opts);
I think this should output me a matrix which will be 11 columns wide by n rows deep (in this case 166 but that number can change hence the use of inf below).
What I actually get is a 166 x 2 cell.
So questions in turn:
  • How do I get it import to appear as a matrix not a cell? (do I even need to care about this, can I address items in a cell the same way?)
  • Why is it bringing it in as 2 columns wide?
Thanks!
  댓글 수: 3
Richard Nash
Richard Nash 2022년 7월 13일
Your suggestion works fine though - so I will go with that. I just overcomplicated it.

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

답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by