Azzera filtri
Azzera filtri

readmatrix() returning "NaN" for all data cells

59 visualizzazioni (ultimi 30 giorni)
Ryan Mosse
Ryan Mosse il 24 Giu 2024 alle 20:48
Modificato: Voss il 25 Giu 2024 alle 17:17
I have run into some trouble using the "readmatrix" function and was wondering if anyone has any insights. I am trying to plot a comparison between a 2D airfoil's Cp distribution as a function of %chord and my aircraft's 3D Cp as a %chord (at a given span position) from XFLR5's .txt files.
When my 3D aircraft does not have wing flaps, the readmatrix function works perfectly; however, when I use the file with flaps I get a column of NaNs as my matrix output. The two files are almost identical spare a few lines close to the start, leading me to be very confused why the second txt file cannot be properly interpreted with the readmatrix() function. Additionally, I don't need any of the data before the y-span row. I have tried other methods such as "readcell" and "readtable" but those either don't work or intrepret the data imporperly. Does anyone have any suggestions?
Thanks!
Here is how I call each of these (pardon my variable naming convention)
"Aoa3MainWing..." is the file which is working correctly and "MainWing..." is the one with errors
Below Screenshots the working file (Aoa3MainWing...)
Above: txt file for no flaps
Above: datafile after readmatrix()
Below Screenshots of the non-working file (MainWing...)
Above: txt file for flaps (only difference ,aside from data values, is "Main WingFlap..." and "Flap 2 Moment..." lines being added)
Above: datafile after readmatrix() producing only a column of NaNs

Risposta accettata

Voss
Voss il 24 Giu 2024 alle 21:08
You can have readmatrix exclude a certain number of lines at the start of the file by specifying the NumHeaderLines argument.
If that can vary, here's some code that figures it out based on the assumption that the data always starts immediately after the first line that starts with "y-span":
data = readmatrix(file_name,'NumHeaderLines',find(startsWith(strtrim(readlines(file_name)),'y-span'),1))
  3 Commenti
Ryan Mosse
Ryan Mosse il 25 Giu 2024 alle 13:39
I tried the line you wrote finding the NumHeaderLines and it seemed to work. Thank you!
Voss
Voss il 25 Giu 2024 alle 15:00
Modificato: Voss il 25 Giu 2024 alle 17:17
You're welcome! Any questions, let me know.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by