Fitting the curve on poyfitn model

6 views (last 30 days)
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 Comment
John D'Errico
John D'Errico on 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.

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 1 Jan 2018
Edited: John D'Errico on 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)
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 Comments
Matt J
Matt J on 1 Jan 2018
Edited: Matt J on 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
John D'Errico on 2 Jan 2018
Edited: John D'Errico on 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.

Sign in to comment.

More Answers (1)

Matt J
Matt J on 1 Jan 2018
Edited: Matt J on 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);

Community Treasure Hunt

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

Start Hunting!