title: generate a matrix image after having all the balck pixel's coordinates with MatLab
body: <p>I have an Image, converted into binary, i got all the black pixel's coordinates.
  The 'matrix' contains the x and y coordinates arranged by columns.
  Now i Need to make a Simulation, to see if my Programme works.
  I have to generate an Matrix Image with my results. </p>
  
  <pre><code>im=imread('square.jpg');
  
  imshow(im); c=im2bw(im); figure; imshow(c);
  
  
  dim = size(c) % size of the image
  x = [];
  y = [];
  xdif = [];
  newx = [];
  matrix = [];
  
  for i = 1:dim(1)
  for j = 1:dim(2)
  
   if c(i,j)==0;
       x = [x i];
       y = [y j];
  
   end
  
  
  end
  
  
  end
  
   % show black pixel's coordinates
     p = [x;y]; 
  
     %number of pixels
     nr = length(x)
  
      dimp = size(p);
  
       xval = p(1,:);
       yval = p(2,:);
  
       j=1;
       i=1;
  
      for z = 1:dimp(2)-1
  
   xdif =  xval(z+1)-xval(z);
   ff=find(xdif &gt; 0); 
  
   if ff == 1
        i = 1;
   else
       i=i+1;
   end
  
    newx(i,j)= xval(z);
    newy(i,j)= yval(z);
  
  
   if ff == 1
      j= j+1;
  
   end
  
  end  
  
  
  xsize = size(newx);
  ysize = size(newy);
  matrix_size = xsize(2)+ysize(2)
  
  xinc = 1;
  yinc = 1;
  x=1;
  
  for ct = 1:1:matrix_size/2
  
  x;
  matrix(:,x) = newx(:,xinc);
  matrix(:,x+1) = newy(:,yinc);
  
  matrix;
  
  xinc = xinc+1;
  yinc = yinc+1;
  
  x=x+3;
  
  end
  
  matrix
  </code></pre>
  
  <p>this is my Programme, now i need to make a simulation, by generating an image with my coordinates.
  how can i do that?
  thank's</p>