readmatrix() returning "NaN" for all data cells

59 次查看(过去 30 天)
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

采纳的回答

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

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by