Filtering Columns by Contents of Rows

1 visualización (últimos 30 días)
Justin Delano
Justin Delano el 30 de Mzo. de 2020
Comentada: Justin Delano el 30 de Mzo. de 2020
I have arrays that look like this:
A =
1 NaN NaN
2 3 4
2 5 NaN
I want to remove columns that contain rows with less than n non-NaN entries. In this case, with n=2, the first column of A would be removed, since the first row contains only 1 non-NaN value. The resulting array would be:
A =
NaN NaN
3 4
5 NaN
Is there a compact way to do this? I hope this explanation makes sense!

Respuestas (1)

Birdman
Birdman el 30 de Mzo. de 2020
n=2;
A(:,(sum(~isnan(A),2)<n).')=[]
  3 comentarios
Birdman
Birdman el 30 de Mzo. de 2020
Try the following line for both cases:
n=2;
A(:,any(~isnan(A) & A<n,1))=[]
Justin Delano
Justin Delano el 30 de Mzo. de 2020
For this new case, it removed the first column, as opposed to the third column, unfortunately.

Iniciar sesión para comentar.

Categorías

Más información sobre Matched Filter and Ambiguity Function en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by