title: How to make Zigzag plot
body: <p>I want to make a zigzag plot in matlab, and have a mathematical formula. Why following does not work:</p>
  
  <pre><code>clc
  clear all
  p=100;
  m=5;
  x=0:1:100;
  
  for 0 &lt; x &lt;= p./m
  y(i) =m.*x;
  end
  
  plot(x,y)
  hold on 
  
  for p./m &lt; x &lt;= 2.*p./m
   y(i) = -m.*x + 2.*p ;
  end
  
  plot(x,y)
  hold on 
  
  
  
  for 2.*p./m &lt; x &lt;= 3.*p./m
   y(i) = m.*x - 2.*p;
  end
  
  plot(x,y)
  </code></pre>