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

1 Ansicht (letzte 30 Tage)
Islam
Islam am 30 Nov. 2013
Beantwortet: Andrei Bobrov am 30 Nov. 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.

Akzeptierte Antwort

Wayne King
Wayne King am 30 Nov. 2013
Bearbeitet: Wayne King am 30 Nov. 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);

Weitere Antworten (2)

Azzi Abdelmalek
Azzi Abdelmalek am 30 Nov. 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 am 30 Nov. 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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by