Borrar filtros
Borrar filtros

get rid of NaNs

2 visualizaciones (últimos 30 días)
Andrea
Andrea el 7 de Jun. de 2012
I have two matrix A and B I want to remove all row and columns with all NaNa in matrix A and accordingly delete the same row and column in B:
A( all( isnan( A ), 2 ), : ) = []; % removes all rows with all nans
A( :, all( isnan( A ), 1 ) ) = []; % and columns
this remove all row and column with all NaNs, But I want to remove the exact row and column from B, too, here is an example:
>> A=[1 2 3 NaN NaN 5 6 7];
>> B=[1 2 3 4 5 6 7 8]; I want the B as below:
B=[1 2 3 6 7 8];
Thanks in advances!

Respuesta aceptada

per isakson
per isakson el 7 de Jun. de 2012
rows_to_be_removed = all( isnan( A ), 2 ),
A(rows_to_be_removed,:)=[];
B(rows_to_be_removed,:)=[];
etc.
Given that A and B have the same size.

Más respuestas (2)

Thomas
Thomas el 7 de Jun. de 2012
A=[1 2 3 NaN NaN 5 6 7];
B=[1 2 3 4 5 6 7 8];
check=find(isnan(A));
B(check)=[]

Andrea
Andrea el 7 de Jun. de 2012
actually it was an simple example. But I want to remove rows with all NaNa and then remove the same rows from another matrix accordingly.

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by