readmatrix() returning "NaN" for all data cells
59 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ryan Mosse
el 24 de Jun. de 2024 a las 20:48
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1721566/image.png)
Below Screenshots the working file (Aoa3MainWing...)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1721571/image.png)
Above: txt file for no flaps
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1721576/image.png)
Above: datafile after readmatrix()
Below Screenshots of the non-working file (MainWing...)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1721581/image.png)
Above: txt file for flaps (only difference ,aside from data values, is "Main WingFlap..." and "Flap 2 Moment..." lines being added)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1721586/image.png)
Above: datafile after readmatrix() producing only a column of NaNs
0 comentarios
Respuesta aceptada
Voss
el 24 de Jun. de 2024 a las 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!