Wrong color showed by "imagesc" function, what am I doing wrong?

3 views (last 30 days)
Hi I have a 3x3 matrix of p-values and I want to display it using a colored grid. I am using the "imagesc" function with a "Copper" color map. One of the grids is coming out in wrong color. What am I doing wrong?
The Matrix is as follows -
resPval =
0.9996 1.0000 1.0000
0.2973 0.9918 1.0000
1.0000 1.0000 1.0000
And I am using the following code the generate the figure-
for i=1:3
for j=1:length(betaVal)
if resHval(i,j); Hstr='H_o Rejected'; col='b'; else Hstr='H_o Accepted'; col='r'; end
This is the figure I am getting-
Why am I getting that black block? Please help me if someone knows.
  1 Comment
Image Analyst
Image Analyst on 7 Mar 2015
The error we get is :
Undefined function or variable 'betaVal'.
Error in test3 (line 8)
for j=1:length(betaVal)

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 7 Mar 2015
The value of resPval is 0.2973 so it shows up in a different color, whereas the other values are all within 1/64 of 1. Since you didn't specify a number of colors, it will use a 64 color colormap and so all values in the range [1-1/64, 1] will be the same color. The one value is for 0.2973 which is not in that range and thus appears with a different color. Which of the two colors you're displaying do you consider the "wrong" color, and why? It's just doing exactly what you told it to.
Udit Gupta
Udit Gupta on 7 Mar 2015
Aah I get it now, the black color is for the 0.2973 value, I am just plotting it wrong. Thanks for your help.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by