フィルターのクリア

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 件のコメント
Kushagra Kirtiman
Kushagra Kirtiman 2022 年 4 月 1 日
Can you explain the process a bit?
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 Center および File ExchangeScatter Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by