Effacer les filtres
Effacer les filtres

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

9 vues (au cours des 30 derniers jours)
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?

Réponse acceptée

Walter Roberson
Walter Roberson le 1 Avr 2022
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 commentaires
Kushagra Kirtiman
Kushagra Kirtiman le 1 Avr 2022
Can you explain the process a bit?
Walter Roberson
Walter Roberson le 1 Avr 2022
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by