title: Rotation of image manually in matlab
body: <p>I am trying to rotate the image manually using the following code.</p>
  
  <pre><code>clc;
  m1 = imread('owl','pgm'); % a simple gray scale image of order 260 X 200
  newImg = zeros(500,500);
  newImg = int16(newImg);
  rotationMatrix45 = [cos((pi/4)) -sin((pi/4)); sin((pi/4)) cos((pi/4))];
  
  for x = 1:size(m1,1)
      for y = 1:size(m1,2)
          point =[x;y] ;
          product = rotationMatrix45 * point;
          product = int16(product);
          newx =product(1,1);
          newy=product(2,1);
          newImg(newx,newy) = m1(x,y);
      end
  end
  imshow(newImg);
  </code></pre>
  
  <p>Simply I am iterating through every pixel of image <code>m1</code>, multiplying m1(x,y) with rotation matrix, I get <code>x',y'</code>, and storing the value of <code>m1(x,y)</code> in to `newImg(x',y')' <strong>BUT</strong> it is giving the following error</p>
  
  <pre><code>??? Attempted to access newImg(0,1); index must be a positive integer or logical.
  
  Error in ==&gt; at 18
          newImg(newx,newy) = m1(x,y);
  </code></pre>
  
  <p>I don't know what I am doing wrong.</p>