How to use the index ? how to drop elements from a matrix ?

1 visualización (últimos 30 días)
Islam
Islam el 30 de Nov. de 2013
Respondida: Andrei Bobrov el 30 de Nov. de 2013
I have a matrix b(j,w) = b(3,4)
b= [
0.0913 NaN NaN NaN
0.0913 NaN NaN NaN
0.0913 NaN NaN NaN ]
and g(j,w)=g(3,4)
60 60 60 60
70 70 70 70
75 75 75 75
I want to drop the elements in g that have a correspondent NAN value in b.

Respuesta aceptada

Wayne King
Wayne King el 30 de Nov. de 2013
Editada: Wayne King el 30 de Nov. de 2013
One of many ways:
b= [
0.0913 NaN NaN NaN
0.0913 NaN NaN NaN
0.0913 NaN NaN NaN ];
g = [60 60 60 60
70 70 70 70
75 75 75 75];
idx = ~isnan(b);
g = g(idx>0);

Más respuestas (2)

Azzi Abdelmalek
Azzi Abdelmalek el 30 de Nov. de 2013
b= [ 0.0913 NaN NaN NaN
0.0913 NaN NaN NaN
0.0913 NaN NaN NaN ]
c=[ 60 60 60 60
70 70 70 70
75 75 75 75]
idx=any(~isnan(b),1)
c=c(:,idx)

Andrei Bobrov
Andrei Bobrov el 30 de Nov. de 2013
b = [0.0913 NaN NaN NaN
0.0913 NaN NaN NaN
0.0913 NaN NaN NaN];
g = [60 60 60 60
70 70 70 70
75 75 75 75];
>> g(~isnan(b))
ans =
60
70
75

Categorías

Más información sobre NaNs 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