readmatrix not doing fixed width delimitation correctly

12 vues (au cours des 30 derniers jours)
Richard Nash
Richard Nash le 13 Juil 2022
Commenté : Richard Nash le 13 Juil 2022
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 commentaires
Richard Nash
Richard Nash le 13 Juil 2022
file attached
Richard Nash
Richard Nash le 13 Juil 2022
Your suggestion works fine though - so I will go with that. I just overcomplicated it.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Data Import and Analysis dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by