imagesc Make all zeros white and all <zeros grey

9 ビュー (過去 30 日間)
Robert
Robert 2015 年 9 月 25 日
回答済み: Walter Roberson 2015 年 9 月 25 日
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

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 9 月 25 日
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])

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by