![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/757264/image.bmp)
help with regression fitting - curvilinear
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Eric Escoto
el 4 de Oct. de 2021
Comentada: Eric Escoto
el 4 de Oct. de 2021
I lost on why the model cant plot a single line after fitting a regression to the data (example data attached).
I'm using,
p = polyfit(data(:,2), data:,1), 2);
ypoly = poly val(p, data(:,2));
figure
plot(data(:,2), data(:,1), 'o')
hold on
plot(data(:,2), ypoly)
The figure looks like this (attached) with lines all over instead of one smooth curve.
0 comentarios
Respuesta aceptada
KSSV
el 4 de Oct. de 2021
Editada: KSSV
el 4 de Oct. de 2021
load('data.mat')
p = polyfit(data(:,2), data(:,1), 2);
xi = linspace(min(data(:,1)),max(data(:,2)),1000) ;
yi = polyval(p, xi);
figure
plot(data(:,2), data(:,1), 'o')
hold on
plot(xi,yi)
You made some syntax errors in the given code. Check with the given code.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/757264/image.bmp)
Más respuestas (0)
Ver también
Categorías
Más información sobre Linear and Nonlinear Regression en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!