I solved the problem by removing the semicolons from the .txt file. Thank you! Trying this didn't cross my mind.
readmatrix returning last column as NaN
7 ビュー (過去 30 日間)
古いコメントを表示
Hello Reader!
I am practicing with figures and am practicing with custom cursors.
To save having a very large matrix in the code instead I have a .txt file with the matrix.
customcursor = readmatrix('smileyfacematrix.txt') ;
As you can see in the image the last column of customcursor is entirely NaN.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1703276/image.png)
This is what the text file looks like.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1703281/image.png)
I can not understand why the last column MATLAB converts entirely to NaN and how I can stop this from happening.
採用された回答
VBBV
2024 年 5 月 24 日
編集済み: VBBV
2024 年 5 月 24 日
@Philip The last column has additional character (semicolon) ' ; ' even though it has numeric data. Use readtable to check that the last column actually has same data as in the text file.
customcursor = readmatrix('smileyfacematrix.txt')
customcursor = readtable('smileyfacematrix.txt')
customcursor.Var16{:};
customcursor = readmatrix('Smileyfacematrix.txt')
2 件のコメント
VBBV
2024 年 5 月 24 日
The file also has another character ' ] ' . One simple option is to delete those characters from the txt file itself and then read the data.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Workspace Variables and MAT-Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!