Cody Problem 25. Remove any row in which a NaN appears

1 visualización (últimos 30 días)
Hidd_1
Hidd_1 el 9 de Abr. de 2021
Respondida: DGM el 9 de Abr. de 2021
I found difficulties with the Problem 25 on Cody here is my solution:
function B = remove_nan_rows(A)
[x,y]=size(A)
[row, col] = find(isnan(A))
B=[];
for i=1:x
if (i ~=row)
B=[B ;A(i,:)]
end
end
for A=1:10, the algorithm didn't work, can someone help me with figuring out what's wrong.
Thanks in advance!
  3 comentarios
DGM
DGM el 9 de Abr. de 2021
Consider that isnan(A) returns a logical array, and that any() can work along a specified direction.
B = A(~any(isnan(A),2),:);
or something like that.
Hidd_1
Hidd_1 el 9 de Abr. de 2021
@DGM Can you please rewite you answer on another comment so I can accept it as an answer!

Iniciar sesión para comentar.

Respuesta aceptada

DGM
DGM el 9 de Abr. de 2021
Okay.
Consider that isnan(A) returns a logical array, and that any() can work along a specified direction.
B = A(~any(isnan(A),2),:);
or something like that.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements 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!

Translated by