readmatrix produces NaN values after parsing a .txt file

120 ビュー (過去 30 日間)
h_chep
h_chep 2020 年 4 月 16 日
Hi there guys,
I've encountered weird phenomena while working with readmatrix(). I produce several .txt files with emphemerides data in an orbital propagator software and want to work on the position and velocity data further in Matlab. The thing is that after parsing those .txt files with readmatrix() I receive weird NaNs in random places. For instance, for your convenience I will only provide matrixA with the least amount of NaNs, but there are other files where the number reaches up to 221, which after parsing results in 2 NaNs (see code section below).
Thing is, when I started to manually check my .txt files, I found out that there are no NaNs in txt files themselves. At the row/col id provided by the find(isnan()) routine, I expected to see smth weird in the txt file itself. However, what I can see is reasonable and expected number, so the problem is probably in the way how I set up readmatrix itself. Can you give me any suggestion on how to deal with this NaN generation issue? I will also attach an archived matrixA.txt for your convenience.
Thanks beforehand!
matrixA=readmatrix('matrixA.txt');
[row,col]=find(isnan(matrixA))
row =
45636
19918
col =
3
4
  3 件のコメント
h_chep
h_chep 2020 年 4 月 20 日
Thank you for your solution! It works perfectly fine!
If you could edit this solution to an answer, I would gladly accept it as an answer.
David Ramirez
David Ramirez 2020 年 8 月 11 日
Thank you!

サインインしてコメントする。

採用された回答

darova
darova 2020 年 4 月 20 日
See this solution
I don't have readmatrix. I tried importdata
A = importdata('matrixA.txt');
data = A.data;
find( isnan(data(:)) )
result
ans =
Empty matrix: 0-by-1

その他の回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 4 月 18 日
The data in your txt file is separated using an irregular number of spaces. For some reason, it confuses readmatrix in a few rows. Try this
data = readmatrix('matrixA.txt', ...
'Delimiter', ' ', ...
'ConsecutiveDelimitersRule', 'join');
  3 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 4 月 20 日
I didn't have this problem in R2020a. There might be some issues fixed in this release.
Luis Fernando Gutierrez Urzua
Luis Fernando Gutierrez Urzua 2022 年 4 月 26 日
This solution worked for me in R2021b. Thanks!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by