Le 02/03/2018 à 16:54, Samuel Gougeon a écrit :
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

or
--> A(~boolean_M) = %nan

to stick to your requirement


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

Reply via email to