MATLAB Answers

How to obtain a surface curve plane located on specific heights and with a different vector of color representation?

조회 수: 1(최근 30일)
level is a (120,4) matrix. The columns correspond from 1 to 4 to X coordinate, Y coordinate, Z coordinate and a C scalar value.
When I use this code:
x = level(:,1);
y = level(:,2);
z = level(:,3);
xv = linspace(min(level(:,1)), max(level(:,1)), 20);
yv = linspace(min(level(:,2)), max(level(:,2)), 20);
[X,Y] = meshgrid(xv, yv);
Z = griddata(x,y,z,X,Y);
hold on
surf(X, Y, Z);
grid on
shading interp
axis equal
colorbar
I obtain this plot:
I would like to obtain a surface which is located exactly as I located this one, following the Z values of hight, but that the colors represent C values and not Z.
The colors of the surf plot should be folliwng this:
Any ideas about how to do it?

  댓글 수: 0

Sign in to comment.

채택된 답변

darova
darova 12 Mar 2020
Use cdata property
[x,y,z] = peaks(20);
c = sphere(19);
surf(x,y,z,'cdata',c)

  댓글 수: 4

표시 이전 댓글 수: 1
Philippe Corner
Philippe Corner 12 Mar 2020
if i use your suggestion
surf(X, Y, Z,'cdata',c);
grid on
shading interp
axis equal
colorbar
I obtain a correct colorbar assocaited to my c values like:
But it doesnt plot surf, Probably because I have a problem with size vector:
x = level(:,1); %size: (120,1)
y = level(:,2); %size: (120,1)
z = level(:,3); %size: (120,1)
c = level(:,4); %size: (120,1)
xv = linspace(min(level(:,1)), max(level(:,1)), 120); %size: (1,120)
yv = linspace(min(level(:,2)), max(level(:,2)), 120); %size: (1,120)
[X,Y] = meshgrid(xv, yv); % X size: (120,120) and Y size: (120,120)
Z = griddata(x,y,z,X,Y); %size: (120,120)
hold on
surf(X, Y, Z,'cdata',c); % c size should be (120,120) but it still being 120,1.
%% Im not sure how to create a (120,120) c value from my data that makes sense.
grid on
shading interp
axis equal
colorbar
Please let me know if i made myself clear with my confussion. thanks for your help

Sign in to comment.

추가 답변(0개)


Translated by