Fitting the curve on poyfitn model

조회 수: 4 (최근 30일)
prashant singh
prashant singh 2018년 1월 1일
편집: John D'Errico 2018년 1월 2일
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