I have make surface plot with x, y and z data but getting reshape error
9 ビュー (過去 30 日間)
古いコメントを表示
Kushagra Kirtiman
2022 年 4 月 1 日
コメント済み: 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]
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?
0 件のコメント
採用された回答
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
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 Exchange で Scatter Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!