Clear Filters
Clear Filters

readmatrix() returning "NaN" for all data cells

59 views (last 30 days)
Ryan Mosse
Ryan Mosse on 24 Jun 2024 at 20:48
Edited: Voss on 25 Jun 2024 at 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

Accepted Answer

Voss
Voss on 24 Jun 2024 at 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 Comments
Ryan Mosse
Ryan Mosse on 25 Jun 2024 at 13:39
I tried the line you wrote finding the NumHeaderLines and it seemed to work. Thank you!
Voss
Voss on 25 Jun 2024 at 15:00
Edited: Voss on 25 Jun 2024 at 17:17
You're welcome! Any questions, let me know.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!