title: MATLAB | f=@(x) function handle with range + conv
body: <p>I have these functions with the code that aims to plot the two signals - x(t) and h(t) - alongside their time range then find the convolution of the two signals. </p>
  
  <p><img src="https://i.stack.imgur.com/VZx2r.jpg" alt="View Functions"></p>
  
  <pre><code>x=@(t) 2.*((-2&lt;=t&amp;&amp;t&lt;=1)+2).^2.*18.*(2&lt;=t&amp;&amp;t&lt;=3).*-9.*((4&lt;=t&amp;&amp;t&lt;=5)-5);
  tx=-2:0.01:5;
  
  h=@(t) 3*(0&lt;=t&amp;&amp;t&lt;=2) -6*((4&lt;=t&amp;&amp;t&lt;=4)-3);
  th=0:0.01:4;
  
  c=conv(x(tx),h(th));
  tc=(tx(1)+th(1)):0.01:(tx(end)+th(end));
  
  figure(1)
  subplot(3,1,1); plot(tx,x(tx));
  subplot(3,1,2); plot(th,h(th));
  subplot(3,1,3); plot(tc,c);
  </code></pre>
  
  <p>However, I got this error.</p>
  
  <pre><code>Operands to the || and &amp;&amp; operators must be convertible to logical scalar values.
  Error in @(t)2.*((-2&lt;=t&amp;&amp;t&lt;=1)+2).^2.*18.*(2&lt;=t&amp;&amp;t&lt;=3).*-9.*((4&lt;=t&amp;&amp;t&lt;=5)-5)
  </code></pre>
  
  <p>I want to use <strong>function handle</strong> to plot them.
  Is there a way to fix this problem?</p>
  
  <p>Thanks in advance for your answers.</p>