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

 Réponse acceptée

Walter Roberson
Walter Roberson le 13 Août 2022

1 vote

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 commentaires

Suchetana Mitra
Suchetana Mitra le 13 Août 2022
Modifié(e) : Suchetana Mitra le 13 Août 2022
So should the command be (d2,d1,z) instead?
the syntax said (x,y,z) so that's what I used
Walter Roberson
Walter Roberson le 13 Août 2022
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 .
Suchetana Mitra
Suchetana Mitra le 13 Août 2022
Ohh in that case what I really want to plot is probably the transpose of this matrix
Suchetana Mitra
Suchetana Mitra le 13 Août 2022
Thank you so much!!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by