title: matlab imagesc, set NaN color without changing colormap - the proper way?
body: <p>simple problem that I could not figure out how to solve <em>properly</em>. Here's the problem and what I gather from sources online:</p>
  <ul>
  <li>I have a sorted vector <code>a</code> including NaN values and want to plot this using <code>imagesc</code> - while specifying the specific color for <code>NaN</code> values (pseudocode below)</li>
  </ul>
  <p>what I know:</p>
  <ul>
  <li><code>NaN</code> values are usually the minimum values in the colorscale</li>
  <li>setting the minimum value in the <code>colormap</code> to my faviorite color <code>[.2 .2 .2]</code> should yield the correct plot, where <code>NaN</code>'s are grey and the rest of the plot has the default colormap.</li>
  </ul>
  <p>Below my two attempts to get a solution for this based on <a href="https://stackoverflow.com/questions/8481324/contrasting-color-for-nans-in-imagesc">this post</a></p>
  <ol>
  <li>Attempt 1 fails because minimum value has same color as <code>NaN</code>:</li>
  </ol>
  <br>
  <pre><code>a=[nan 1:10]; %sorted vector with NaN values
  figure; imagesc(a) % display this
  c=colormap; %get colormap
  colormap([.2 .2 .2;c]) %specify NaN color
  </code></pre>
  <p>result:</p>
  <p><a href="https://i.stack.imgur.com/5FTt1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5FTt1.png" alt="enter image description here" /></a></p>
  <br>
  <ol start="2">
  <li>Attempt 2 fails because minimum value is not actually the minimum value of the colorscale (here I guess <code>parula</code>).</li>
  </ol>
  <br>
  <pre><code>a=[nan 1:10];
  figure; imagesc(a)
  c=colormap;
  colormap([.2 .2 .2;c])
  caxis([-1 10]) %set color axis minimum to below the actual values plotted
  </code></pre>
  <p>result:</p>
  <p><a href="https://i.stack.imgur.com/z1Agt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/z1Agt.png" alt="enter image description here" /></a></p>
  <p>Obviously I could set <code>caxis</code> to a tighter interval (e.g. <code>caxis([-.1 10])</code> to approximate the 'original' colormap, but this is just not the 'right way' to go about this... can someone point out how to do this properly?</p>
  <p>PS: an easy way out is to set the <code>AlphaData</code> of the <code>NaN</code> values, however this does not have the flexibility of setting whatever color you want (in this case... grey)</p>