Asked by Yu Zou
on 18 Jan 2018

Greeting everyone!

What i have now is 3 Matrix x,y,z, which can be presented by surf(x,y,z).

But i want to transfer these data to one matrix containing height value, which can be presented by surf(f).

Thanks!

Here is my data:

[x,y,z] = sphere; % Makes a 21-by-21 point sphere

x = x(11:end,:); % Keep top 11 x points

y = y(11:end,:); % Keep top 11 y points

z = z(11:end,:); % Keep top 11 z points

r = 3; % r radius value

x=r*x+r;

y=r*y+r; % Move x, y starting from 0

z=r*z; % Change the radius of the dom to r

% so i generate a dom(half ball) with radius 3

Answer by Image Analyst
on 18 Jan 2018

Try interp2() to take your coordinates and make a 2-D matrix where the values are the z values.

Yu Zou
on 19 Jan 2018

it shows error as below: Error using interp2>makegriddedinterp (line 239) Input grid is not a valid MESHGRID.

Error in interp2 (line 138) F = makegriddedinterp(X, Y, V, method,extrap);

I guess it's because what i want to interpolate is a dom, which doesn't have value in the corners. Do you have any solution?

Image Analyst
on 19 Jan 2018

Yu Zou
on 19 Jan 2018

Thanks for advice, i've attached my code

Sign in to comment.

Answer by Walter Roberson
on 19 Jan 2018

F = scatteredInterpolant(x(:),y(:),z(:));

[X,Y] = ndgrid(1:floor(max(x(:))));

Z = F(X,Y);

surf(Z)

You will find this rather unsatisfactory, but it is the best that can be done while maintaining the axes labels with a simple surf(Z)

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Walter Roberson (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/377825-how-to-transfer-surf-x-y-z-to-a-data-contains-height-value#comment_526078

## Yu Zou (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/377825-how-to-transfer-surf-x-y-z-to-a-data-contains-height-value#comment_526264

Sign in to comment.