title: Convert image to png byte array in Matlab
body: <p>I would like to take a 512x512 image and convert it into a png byte array in Matlab so that I can stream it via a socket.</p>
  
  <p>At the moment I take the array, write it to a png file using imwrite(I,'file.png'), then read it as a binary file and send it through the socket. This is obviously horribly inefficient because I first write to disk and then read from disk. I want to skip the and write to disk.</p>
  
  <p>Is there anyway to do this in Matlab? </p>