필터 지우기
필터 지우기

Colormap: set color for ranges

조회 수: 1 (최근 30일)
Colby
Colby 2015년 7월 1일
댓글: Colby 2015년 7월 2일
I have a matrix that represents a model grid. Non active grid cells are represented by nan within the matrix, cells that don't have data are represented with a zero, and then the rest of the cells are represented with either a positive or a negative number. I want to plot them such that the nan values are all one color, all values that are exactly 0 are one number, values greater than 0 are all one color, and values less than 0 are all one color. I'm at a loss trying to figure out how to do this. Does anyone know how I can accomplish this? Thanks!

채택된 답변

Walter Roberson
Walter Roberson 2015년 7월 2일
colorid = sign(DataMatrix) + 3; %negative -> 2, 0 -> 3, positive -> 4
colorid(isnan(colorid)) = 1;
Now nan are 1, negative are 2, 0 are 3, positive are 4. From there you can create 4 x 3 color table such as
colortab = [32 32 32; 0 128 0; 256 0 0; 0 0 0]./256;
image(colorid)
colormap(colortab);
  댓글 수: 1
Colby
Colby 2015년 7월 2일
This is fantastic! Simple but yet I wouldn't have ever figured it out. Thanks so much for the help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Orange에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by