How to do a heat map ( color the surface) in a 2D plot ?

92 vues (au cours des 30 derniers jours)
Emilie M
Emilie M le 20 Juin 2017
Hello,
I have 3 parameters, x, y and z. And I would like to represent z as a colored surface like in the picture.
Here is my code:
dataTG=xlsread('dataTG.xlsx');
IC50A=9456
IC50B=14.75
X=((dataTG(:,2))./IC50A);
Y=((dataTG(:,3))./IC50B);
TT=(dataTG(:,2)./IC50A)+(dataTG(:,3)./IC50B)
z=(10.^((1-(X./TT)).*(1-(Y./TT)).*(0.78369.*(X./TT)+2.0178.*(Y./TT)-1.9924.*(X./TT).*(Y./TT)+4.7444.*(X./TT).*(Y./TT).*((X./TT)-(Y./TT)))));
figure
refline(-1,1)
hold on
pointsize = 10;
scatter(X, Y, pointsize, z)
colorbar()
Then, to do z as a colored surface, I tried :
[X,Y] = meshgrid(X,Y);
surf(z,'EdgeColor','None');
view(2);
but they say it does not work because 'Z must be a matrix, not a scalar or vector'.
Do you have have any idea ?
Thank you for your help.

Réponses (2)

KSSV
KSSV le 21 Juin 2017
[X,Y] = meshgrid(X,Y);
Z = repmat(z,1,length(x)) ;
surf(X,Y,Z);
shading interp
view(2);

Walter Roberson
Walter Roberson le 21 Juin 2017
dataTG=xlsread('dataTG.xlsx');
IC50A=9456
IC50B=14.75
x = ((dataTG(:,2))./IC50A);
y = ((dataTG(:,3))./IC50B);
[X, Y] = meshgrid(x, y);
TT = (X./IC50A) + (y./IC50B);
Z = (10.^((1-(X./TT)).*(1-(Y./TT)).*(0.78369.*(X./TT)+2.0178.*(Y./TT)-1.9924.*(X./TT).*(Y./TT)+4.7444.*(X./TT).*(Y./TT).*((X./TT)-(Y./TT)))));
figure
refline(-1,1)
hold on
pointsize = 10;
surf(X, Y, Z, 'edgecolor', 'none');
colorbar()

Community Treasure Hunt

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

Start Hunting!

Translated by