Plot matrix values as colors in a checkerboard pattern

7 次查看(过去 30 天)
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
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