title: How do I create an image matrix with a line drawn in it in MATLAB?
body: <p>I want to plot a line from one well-defined point to another and then turn it into an image matrix to use a Gaussian filter on it for smoothing. For this I use the functions <code>line</code> and <code>getframe</code> to plot a line and capture the figure window in an image, but <code>getframe</code> is very slow and not very reliable. I noticed that it does not capture anything when the computer is locked and I got an <code>out of memory</code> error after 170 executions.</p>
  
  <p>My questions are:</p>
  
  <ul>
  <li>Is there a substitute to <code>getframe</code> that I can use?</li>
  <li>Is there a way to create the image matrix and draw the line directly in it?</li>
  </ul>
  
  <p>Here is a minimal code sample:</p>
  
  <pre><code>figure1=line([30 35] ,[200 60]);
  F= getframe;
  hsize=40; sigma=20;
  h = fspecial('gaussian',hsize,sigma); 
  filteredImg = imfilter(double(F.cdata), h,256);
  imshow(uint8(filteredImg));
  </code></pre>
  
  <p><strong>[update]</strong></p>
  
  <p>High-Performance Mark's idea with <code>linspace</code> looks very promising, but how do I access the matrix coordinates calculated with <code>linspace</code>? I tried the following code, but it does not work as I think it should. I assume it is a very simple and basic MATLAB thing, but I just can not wrap my head around it:</p>
  
  <pre><code>matrix=zeros(200,60);
  diagonal=round([linspace(30,200,numSteps); linspace(35,60,numSteps)]);
  matrix(diagonal(1,:), diagonal(2,:))=1;
  imshow(matrix);
  </code></pre>