caxis and colorbar and imagesc; Scaling issue??

2 views (last 30 days)
I am trying to use a subplot to plot probabilities (0->1) with a colorbar.
function myFunc()
%%get A
K = 10;
A1 = get_defaultA(K);
A2 = get_defaultA(K);
A3 = get_defaultA(K);
A4 = get_defaultA(K);
figure;
hold all;
subplot(221);
imagesc(A1);
subplot(222);
imagesc(A2);
subplot(223);
imagesc(A3);
subplot(224);
imagesc(A4);
%%Colorbar on subplots
myMin = 0;
myMax = 1;
axes('Position', [0.095 0.05 0.9 0.9], 'Visible', 'off');
c = colorbar;
%%All is fine up until here;
caxis([myMin, myMax]); % run this and the colors do not match the values in the matrix...
colormap(hsv); %run this and something else odd happens...
end
function P_norm = get_defaultA(K)
P_norm = 0.5.*eye(K,K);
for i=1:K
for j=1:K
if (P_norm(i,j)==0)
P_norm(i,j) = 0.5/(K-1);
end
end
end
end
If you run the above code, put a breakpoint at caxis and a breakpoint at colormap.
First inspect the value of matrices and see that they contain values 0.05 and 0.5 only.
You see that on going into caxis, the colors do not map to the known values of the matrices. odd. why not? Can anyone tell me what I have done wrong.
Secondly, I then wish to use the hsv color scheme, and doing this gives a fully red matrix, again Can anyone tell me what I have done wrong?
many thanks (using 2012A on win7)

Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!