Fitting the curve on poyfitn model
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
prashant singh
le 1 Jan 2018
Modifié(e) : John D'Errico
le 2 Jan 2018
i have 3d data and i have created curve on the data using the polyfitn function. Once i have the polyfitn model how can i use polyvan to get my values to plot the curve. Here is the set of command i have use and the error i am getting using polyvaln function
load data.mat
X = data(:,1);
Y =data(:,2);
Z =data(:,3);
p= polyfitn([X,Y],Z,3);
s = 1:92;
polyvaln(p,s);
Error using polyvaln (line 39)
Size of indepvar array and this model are inconsistent.
1 commentaire
John D'Errico
le 1 Jan 2018
Please stop asking the same question on the very same data. This is now at least the third time you have asked this question.
Réponse acceptée
John D'Errico
le 1 Jan 2018
Modifié(e) : John D'Errico
le 1 Jan 2018
I saw this data the last time you asked a question about it. NO YOU CANNOT USE POLYFITN. PERIOD. If you could have used polyfitn, I would have suggested it. this data is simply not usable to support a multivariate polynomial model.
Worse, as I said in my response to your last question, you have errors in the variables, thus noise in each of x, y, and z. That makes modeling more difficult too.
To be honest, I think use of polyfit itself is of limited utility from what I saw in your last question.
x = data(:,1);
y = data(:,3);
z = data(:,2);
K = z >= 2;
plot3(x(K),y(K),z(K),'o')
box on
grid on
view(76,6)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/180536/image.jpeg)
I would note that depending on how I rotate that data, it looks very different.
view(177,30)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/180538/image.jpeg)
In the first view, we see what looks like a curve. That was how you showed that data in your first question.
In the second figure, we see that the identical data is now apparently a small portion of a surface. It is not enough of a surface to fit a multivariate polynomial model to it. Nor would I ever recommend use of polyfitn there.
As well, see that since you have a SURFACE, the use of polyfit is also not appropriate. You cannot use polyfit to build a surface model.
2 commentaires
Matt J
le 1 Jan 2018
Modifié(e) : Matt J
le 1 Jan 2018
as I said in my response to your last question, you have errors in the variables, thus noise in each of x, y, and z.
In fact, there are no errors in z. The z data is just a perfectly consecutive sequence of integer indices. x and y are functions of z, though what the model should be seems an open question.
John D'Errico
le 2 Jan 2018
Modifié(e) : John D'Errico
le 2 Jan 2018
There is no model that will suffice here though. A polynomial model is insane. It also makes no sense to fit y(z) and x(z) independently.
Plus de réponses (1)
Matt J
le 1 Jan 2018
Modifié(e) : Matt J
le 1 Jan 2018
I don't think you need polyfitn for what you are doing. It can be done simply enough with the regular polyfit,
load data.mat
idx=data(:,2)<150; data(idx,:)=[]; %discard bad data
X = data(:,1);
Y = data(:,2);
Z = data(:,3);
px = polyfit(Z,X,3);
py = polyfit(Z,Y,3);
s=1:92;
xFit=polyval(px,s);
yFit=polyval(py,s);
0 commentaires
Voir également
Catégories
En savoir plus sur Get Started with Curve Fitting Toolbox 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!