Le 02/03/2018 à 16:40, fujimoto2005 a écrit :
In the attached code,"boolean_M" is a random Boolean matrix.
I want to get the average of each column of A whose corresponding element of
boolean_M has "true" as row vector x_V, but it does not work.
Where am I wrong?
n=10;
boolean_M=rand(n,n)>0.5;
disp(boolean_M)
A=rand(n,n);
disp(A);
x_V=mean(A(boolean_M),'r');

Instead, you may use

n  =  5;
boolean_M  =  rand(n,n)>0.5
A  =  grand(n,n,"uin",0,9)
A(boolean_M)  =  %nan
nanmean(A,"r")

--> n = 5;
--> boolean_M = rand(n,n)>0.5
 boolean_M  =
  T F F F T
  T T T T T
  T T F T T
  F T F T F
  F F T T F

--> A = grand(n,n,"uin",0,9)
 A  =
   6.   2.   5.   4.   6.
   6.   9.   3.   6.   5.
   3.   9.   3.   5.   4.
   0.   8.   7.   0.   7.
   1.   6.   8.   7.   2.

--> A(boolean_M) = %nan
 A  =
   Nan   2.    5.    4.    Nan
   Nan   Nan   Nan   Nan   Nan
   Nan   Nan   3.    Nan   Nan
   0.    Nan   7.    Nan   7.
   1.    6.    Nan   Nan   2.

--> nanmean(A,"r")
 ans  =
   0.5   4.   5.   4.   4.5

Samuel

_______________________________________________
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users

Reply via email to