Fitting the curve on poyfitn model

4 次查看(过去 30 天)
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 个评论
John D'Errico
John D'Errico 2018-1-1
Please stop asking the same question on the very same data. This is now at least the third time you have asked this question.

请先登录,再进行评论。

采纳的回答

John D'Errico
John D'Errico 2018-1-1
编辑:John D'Errico 2018-1-1
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)
I would note that depending on how I rotate that data, it looks very different.
view(177,30)
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 个评论
Matt J
Matt J 2018-1-1
编辑:Matt J 2018-1-1
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
John D'Errico 2018-1-2
编辑:John D'Errico 2018-1-2
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.

请先登录,再进行评论。

更多回答(1 个)

Matt J
Matt J 2018-1-1
编辑:Matt J 2018-1-1
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);

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by