imagesc Make all zeros white and all <zeros grey

9 vues (au cours des 30 derniers jours)
Robert
Robert le 25 Sep 2015
I asked a very similar question a few hours ago and was given the answer I was looking for at the time, but I have jsut realized that I need to slightly modify my question
I have successfully made all the zeros in my imagesc plot white using the following code
figure(1)
imagesc(testNSE);
title ('Model vs Observations All NSE')
caxis([0, 1])
myColorMap = jet(256);
myColorMap(1,:) = 1;
colormap(myColorMap);
colorbar
however I have just realized that this makes all zeros and values <zero white. Now I need all zeros white and all <zeros gray (or another specified color). The colorbar should still only maintain a scale from 0-1.
I have tried creating multiple colourmaps but have had no success and now I am stuck
Thank you in advance for any help

Réponses (1)

Walter Roberson
Walter Roberson le 25 Sep 2015
I had to make an arbitrary choice about what to do with the data that is greater than 0 but small enough that it would quantize down to one of the reserved slots, so I moved it all to the first non-reserved slot.
cmap = jet(256);
cmap(1,:) = 0.8;
cmap(2,:) = 1;
cmapsize = size(cmap,1);
maxval = max(testNSE(:));
scaledNSE = (testNSE / maxval) * cmapsize; %could be negative or 0
smallNSE = (scaledNSE > 0 & scaledNSE < 3);
scaledNSE(testNSE < 0) = 1;
scaledNSE(testNSE == 0) = 2;
scaledNSE(smallNSE) = 3;
image(scaledNSE); %caution: imshow() or imagesc() might give different results
colormap(cmap);
caxis([0 cmapsize-1])

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by