Wrong color showed by "imagesc" function, what am I doing wrong?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Udit Gupta
el 7 de Mzo. de 2015
Comentada: Udit Gupta
el 7 de Mzo. de 2015
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-
colormap('copper')
imagesc(resPval)
for i=1:3
for j=1:length(betaVal)
Pstr=num2str(resPval(i,j),8);
if resHval(i,j); Hstr='H_o Rejected'; col='b'; else Hstr='H_o Accepted'; col='r'; end
text(i,j,{Pstr,Hstr},...
'HorizontalAlignment','center',...
'VerticalAlignment','middle',...
'BackgroundColor','w',...
'Color',col);
end
end
set(gca,'YTick',1:length(betaVal),'YTickLabel',colNames,'XTick',1:3,'XTickLabel',rowNames(1:3))
This is the figure I am getting-
Why am I getting that black block? Please help me if someone knows.
1 comentario
Image Analyst
el 7 de Mzo. de 2015
The error we get is :
Undefined function or variable 'betaVal'.
Error in test3 (line 8)
for j=1:length(betaVal)
Respuesta aceptada
Image Analyst
el 7 de Mzo. de 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.
3 comentarios
Image Analyst
el 7 de Mzo. de 2015
By the way, your label locations are wrong. You're using resHval(i,j) for the values, but in text(x,y,string) you're using text(i,j,string). But i is row, which is the y value, and j is the column which is the x value. So you're really doing text(y, x, string), not text(x,y,string) like you think. Don't worry - it's a very very common mistake that all novices make: mixing up row,column with x,y.
Más respuestas (0)
Ver también
Categorías
Más información sobre Orange en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!