Borrar filtros
Borrar filtros

NaN with backslash operator

12 visualizaciones (últimos 30 días)
Sun
Sun el 29 de Abr. de 2019
Editada: Sun el 31 de Jul. de 2019
Hi,
I would like to understand the reason as to why the below operation is giving a NaN solution for the attached data.
x = A\B;
Thank you.
YK..

Respuesta aceptada

Adam Danz
Adam Danz el 29 de Abr. de 2019
The following rows of your variable "B" contain NaN values.
find(isnan(B))
ans =
1491
1492
1493
1494
1495
1496
1497
To ignore the NaN values,
nanIdx = isnan(A) | isnan(B);
A(~nanIdx) \ B(~nanIdx)
ans =
-0.091457
  2 comentarios
John D'Errico
John D'Errico el 29 de Abr. de 2019
The problem being that NaNs propagate. Everything they touch, turns to NaN. (Like old King MIdas, but in an even worse way.) So if you already have NaNs in your data, give it up. You need to excise them from your data before any linear algebra computations.
Steven Lord
Steven Lord el 29 de Abr. de 2019
FYI the functions listed in the "Missing Data and Outliers" section of this documentation page may be of use in locating, removing, and/or replacing the NaN values in the data.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by