How do i assigning a color to a range of numbers in an image array?
조회 수: 5 (최근 30일)
이전 댓글 표시
I am currently attempting to assign the color red to all the negative values in an 2D array and the color green to all the positive values in an 2D array. If the value is 0, i want the color displayed to be yellow. The background value should be white.
Example array:
A = [ 9899 9899 9899 9899 9899
9899 -90 0 70 9899
9899 9899 -20 30 9899
9899 9899 9899 9899 9899];
9899 represents the background color, which should be white. The zeros should be yellow. All colors should be uniform and there should not be a color gradient.
I would expect an output colormap that looks similar to this(without labels):
I have tried the imagesc function but i do not know how to set up the proper ranges/limits for the desired colors to appear.
I would greatly appreciate any feedback. Thank you in advance!
댓글 수: 0
채택된 답변
Stephen23
2019년 10월 21일
A = [9899,9899,9899,9899,9899;9899,-90,0,70,9899;9899,9899,-20,30,9899;9899,9899,9899,9899,9899];
% backgnd; neg; zero; pos;
rgb = [1,1,1;1,0,0;1,1,0;0,1,0];
idx = 2*(A<0) + 3*(A==0) + 4*(A>0);
idx(A==9899) = 1;
image(idx)
colormap(rgb)
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!