title: Encode an image as a base64 string in MATLAB
body: <p>Currently, I have an image stored as an <code>MxNx3 uint8</code> array in MATLAB. However, I need to embed it in an HTML document, and I can't include the image separately.</p>
  
  <p>Instead, I've decided to try and encode the image as a <code>base64</code> string. However, I can't seem to find a way to encode the image as a string <em>without</em> having to first save the image to disk. I tried looking into <code>writebmp</code> and the like, but I can't seem to get it to work.</p>
  
  <p>I'd really rather not <em>write</em> the image to a file, just to read it back using <code>fread</code>. The computer I'm using has very low Disk I/O, so that will take <em>way</em> too long.</p>
  
  <p>Any help would be appreciated!</p>
  
  <h2>Edit:</h2>
  
  <p>I looked <a href="https://www.mathworks.com/matlabcentral/fileexchange/39526-byte-encoding-utilities?focused=3773214&amp;tab=function" rel="nofollow noreferrer">here</a>, but that errors in R2018b due to "no method found". When I linearize the image, the returned string is incorrect</p>