<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Le 02/03/2018 à 16:40, fujimoto2005 a
      écrit :<br>
    </div>
    <blockquote cite="mid:1520005241921-0.post@n3.nabble.com"
      type="cite">
      <pre wrap="">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?</pre>
    </blockquote>
    <blockquote type="cite">
      <pre>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');
</pre>
    </blockquote>
    <br>
    Instead, you may use<br>
    <pre style="font-family:Monospaced;font-style:normal;font-size:12.0;"><span style="color:rgb(0,0,0);">n</span> <span style="color:rgb(92,92,92);">=</span> <span style="color:rgb(188,143,143);">5</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(0,0,0);">boolean_M</span> <span style="color:rgb(92,92,92);">=</span> <span style="color:rgb(50,185,185);">rand</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">n</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">n</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(92,92,92);">></span><span style="color:rgb(188,143,143);">0.5</span>
<span style="color:rgb(0,0,0);">A</span> <span style="color:rgb(92,92,92);">=</span> <span style="color:rgb(50,185,185);">grand</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">n</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">n</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(188,143,143);">uin</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">0</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">9</span><span style="color:rgb(74,85,219);">)</span>
<span style="color:rgb(0,0,0);">A</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">boolean_M</span><span style="color:rgb(74,85,219);">)</span> <span style="color:rgb(92,92,92);">=</span> <span style="color:rgb(218,112,214);">%nan</span>
<span style="color:rgb(255,102,0);">nanmean</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">A</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(188,143,143);">r</span><span style="color:rgb(188,143,143);">"</span><span style="color:rgb(74,85,219);">)</span></pre>
    <font size="-1"><tt>--> n = 5;</tt><tt><br>
      </tt><tt>--> boolean_M = rand(n,n)>0.5</tt><tt><br>
      </tt><tt> boolean_M  = </tt><tt><br>
      </tt><tt>  T F F F T</tt><tt><br>
      </tt><tt>  T T T T T</tt><tt><br>
      </tt><tt>  T T F T T</tt><tt><br>
      </tt><tt>  F T F T F</tt><tt><br>
      </tt><tt>  F F T T F</tt><tt><br>
      </tt><tt> </tt><tt><br>
      </tt><tt>--> A = grand(n,n,"uin",0,9)</tt><tt><br>
      </tt><tt> A  = </tt><tt><br>
      </tt><tt>   6.   2.   5.   4.   6.</tt><tt><br>
      </tt><tt>   6.   9.   3.   6.   5.</tt><tt><br>
      </tt><tt>   3.   9.   3.   5.   4.</tt><tt><br>
      </tt><tt>   0.   8.   7.   0.   7.</tt><tt><br>
      </tt><tt>   1.   6.   8.   7.   2.</tt><tt><br>
      </tt><tt></tt><tt><br>
      </tt><tt>--> A(boolean_M) = %nan</tt><tt><br>
      </tt><tt> A  = </tt><tt><br>
      </tt><tt>   Nan   2.    5.    4.    Nan</tt><tt><br>
      </tt><tt>   Nan   Nan   Nan   Nan   Nan</tt><tt><br>
      </tt><tt>   Nan   Nan   3.    Nan   Nan</tt><tt><br>
      </tt><tt>   0.    Nan   7.    Nan   7. </tt><tt><br>
      </tt><tt>   1.    6.    Nan   Nan   2. </tt><tt><br>
      </tt><tt><br>
      </tt><tt>--> nanmean(A,"r")</tt><tt><br>
      </tt><tt> ans  =</tt><tt><br>
      </tt><tt>   0.5   4.   5.   4.   4.5</tt><tt><br>
      </tt></font><br>
    Samuel<br>
    <br>
  </body>
</html>