Discrepancy in imagesc from given matrix

I want to plot a heatmap of a matrix with corresponding values of d1 and d2 using imagesc
%Relevant code
d1=linspace(0.1,2.2,200);
d2=linspace(0.1,2.2,200);
x=d1;
y=d2;
z=readmatrix('Plant.csv');
imagesc(x,y,z)
colorbar
colormap(flipud(hot))
set(gca,'YDir','normal')
d1(150)=1.67
d2(50)=0.6
z(150,50)=0.43
However according to the plot z(150,50)=0; this is very confusing to me am I using imagesc wrong

 Accepted Answer

Remember that z(150,50) is z at the 150th Y value and the 50th X value. Rows correspond to Y not to X.

4 Comments

So should the command be (d2,d1,z) instead?
the syntax said (x,y,z) so that's what I used
Your d1 and d2 are the same, so it doesn't matter if you surf(d1,d2,z) or surf(d2,d1,z)
surf(x,y,z) is correct syntax, and the way you created x and y are fine.
The difficulty is that you are looking at z(150,50) and thinking that displays at the 150'th x and the 50'th y, when instead it displays at the 150'th y and the 50'th x. The problem is not with constructing the x and y and z or the surf, the problem is your mental mapping from row and column to x and y. Row --> y, column --> x .
Ohh in that case what I really want to plot is probably the transpose of this matrix
Thank you so much!!

Sign in to comment.

More Answers (0)

Products

Release

R2022a

Community Treasure Hunt

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

Start Hunting!