Imagesc plot (dividing the colorbar to blue-green, white, and green-red range)

1 回表示 (過去 30 日間)
Ronaldo
Ronaldo 2014 年 5 月 8 日
コメント済み: Image Analyst 2014 年 5 月 10 日
I want to plot the values of a matrix ranging from -10 to 10 in a way that I can assign
1) Dark blue color to * green * to the values between -10 and -5
2) White color to values between -5 and 5
3) * Green * to dark red to values between 5 and 10
It is important that I do not like to miss any color in the range of white; i.e., step 3 must begin with the color that step 1 ends with.
I could write the following which is able to plot values of a matrix which are zero or positive and assign green to red color to values larger than 0.
A=[9 9.1 8.3 0 0;
0 9.5 8.4 0 0;
0 0 9.6 8.3 8.1;
0 7.1 7 9.7 0];
lowestValue = min(A(A(:)>0))
highestValue = max(A(:))
imagesc(A);
cmap = jet(256);
colormap(cmap(120:256,:));
caxis(gca,[lowestValue-2/256, highestValue]);
for i=1:120
cmap(i,:)=[1,1,1];
end
colormap(cmap(120:256,:))
colorbar

回答 (1 件)

Image Analyst
Image Analyst 2014 年 5 月 10 日
Do you have a question? I mean other than how do I format my code properly? And if you wanted a colormap like you said, why did you use jet(256)? And did you know that i does not appear in your loop anywhere so you're just setting the same row #120 over and over again 120 times?
  2 件のコメント
Ronaldo
Ronaldo 2014 年 5 月 10 日
So many thanks for your reply.I am not expert at MATLAB so maybe my code is not correct.I will delete the code if you think that it misleads others. For me it is only important to be able to plot the following.
I want to plot the values of a matrix ranging from -10 to 10 in a way that I can assign
1) Dark blue color to * green * to the values between -10 and -5
2) White color to values between -5 and 5
3) * Green * to dark red to values between 5 and 10
It is important that I do not like to miss any color in the range of white; i.e., step 3 must begin with the color that step 1 ends with.
Image Analyst
Image Analyst 2014 年 5 月 10 日
How about an interactive way of creating one? Have you tried colormapeditor ()?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOrange についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by