I have make surface plot with x, y and z data but getting reshape error

9 次查看(过去 30 天)
x=[ 10 21 29 39 52]
y=[ 143.44 130.4 134.89 123.71 130.4]
z=[ 93.66 107.1 102.2 113.39 107.1]
xi = reshape(x,5,5);
yi = reshape(y,5,5);
zi = reshape(z,5,5);
I am getting error in reshape function. Without converting it to matrix I cannot use Surf function. Can anyone help me with this?

采纳的回答

Walter Roberson
Walter Roberson 2022-4-1
x=[ 10 21 29 39 52];
y=[ 143.44 130.4 134.89 123.71 130.4];
z=[ 93.66 107.1 102.2 113.39 107.1];
F = scatteredInterpolant(x(:), y(:), z(:));
N = 100;
xvec = linspace(min(x), max(x), N);
yvec = linspace(min(y), max(y), N);
[X, Y] = meshgrid(xvec, yvec);
Z = F(X, Y);
surf(X, Y, Z, 'edgecolor', 'none')
  2 个评论
Walter Roberson
Walter Roberson 2022-4-1
You do not have a regular grid of data, so reshape() is not going to work. Instead you have a "scattered interpolation" situation. There are a few different functions that can deal with scattered interpolation; the one used most commonly in this situation is scatteredInterpolant() (but griddata() gets used a lot too.)
To use scatteredInterpolant() the first thing you do is create an interpolant object. This does some kind of internal pre-arrangement of the data and stores it in an Object.
Next, you want to use the interpolant object to interpolate for a grid of locations -- because surf() needs a grid of locations and corresponding values. You have to decide which locations you want to interpolate that. You might have specific reasons to interpolate over a particular range, but if not then it is common to use the minimum and maximum values of the input coordinates as the limits. You can use linspace() to build vectors of intermediate x and y values, and meshgrid() to create a grid of X and Y points you want to query at.
Then you invoke the interpolating object at the grid of query points, getting an array of output. And then you draw it.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by