title: Operands to the || and && operators must be convertible to logical scalar values
body: <p>I have a simple problem that I'm looking for a fast implementation in Matlab. I have an array of values, let's say:</p>
  
  <pre><code> a = floor(rand(5,5).*255)
  </code></pre>
  
  <p>I then have a similarly sized threshold array, let's say it's:</p>
  
  <pre><code>a_thresh = floor(rand(5,5).*255)
  </code></pre>
  
  <p>For values within <code>a</code> if they are 0.5x smaller than the corresponding value in <code>a_thresh</code> I want the output to be 0 - similarly for 1.2x the value in <code>a_thresh</code> should also be set to zero, <em>i.e.</em>:</p>
  
  <pre><code>a(a &lt; a_thresh.*0.4) = 0
  a(a &gt; a_thresh.*1.2) = 0
  </code></pre>
  
  <p>For values between 0.4x and 0.5x and 1.0x and 1.2x I want a proportional amount and else where between 0.5 and 1.0 I want to use the value of <code>a</code> unaltered. I thought I could use something like the following:</p>
  
  <pre><code> a(a&gt;= a_thresh .* 0.4 &amp;&amp; a &lt;a_thresh.* 0.5) = ((a - a_thresh.*0.4)/(a_thresh.*0.5 a_thresh.*0.4)) .* a;
  </code></pre>
  
  <p>However, I get an error that says:</p>
  
  <blockquote>
    <p>Operands to || and &amp;&amp; operations must be convertible to logical scalar values</p>
  </blockquote>
  
  <p>Any advice on how to solve this? Obviously I could use loops to do this and it would be trivial, but I want to keep the code vectorized.</p>