필터 지우기
필터 지우기

Plot matrix values as colors in a checkerboard pattern

조회 수: 4 (최근 30일)
Søren Holm-Petersen
Søren Holm-Petersen 2020년 5월 4일
댓글: Søren Holm-Petersen 2020년 5월 5일
Hi
I have the following matrix
C = [-1 -1 0.155;
0.150 -1 0.152;
0.140 0.143 0.148];
I would like to plot each value as a colored cell in a checkerboard pattern. The "-1" values are throwaway data, and should be marked by a red cell. The rest of the cells should have some color scale, so to be distinguishable from each other. Is this possible?
I tried using the suggestion by Cam in this answer, and it almost does what I want. However the negative values become purple, and the rest yellow. I'm guessing because the colorscale is applied to the range [-1,0.155], and all the actual data values are very close.
Regards
Søren

채택된 답변

Tommy
Tommy 2020년 5월 4일
Why red? What if some real data is mapped to red?
You are right about the -1 values messing things up. But the 0s on the border (from the answer in your link) also mess things up.
You could replace all -1s with NaN and pad with NaNs instead of 0s:
C0 = [-1 -1 0.155;
0.150 -1 0.152;
0.140 0.143 0.148];
C = C0;
C(C == -1) = NaN;
C = [[C nan(size(C,1),1)] ; nan(1,size(C,2)+1)];
pcolor(C)
This leaves the -1 squares completely blank. One way to set them to red would be to color the underlying axes to red:
C0 = [-1 -1 0.155;
0.150 -1 0.152;
0.140 0.143 0.148];
C = C0;
C(C == -1) = NaN;
C = [[C nan(size(C,1),1)] ; nan(1,size(C,2)+1)];
ax = axes;
pcolor(ax, C)
ax.Color = 'r';
  댓글 수: 1
Søren Holm-Petersen
Søren Holm-Petersen 2020년 5월 5일
Hi Tommy
Thanks for the answer. It was wrong to call the -1 values "throwaway data". I have an algorithm which I have evaluated at some (x,y) values. Whenever the algorithm reports failure to complete the task, it outputs -1.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by