problem with polyfit function
4 次查看(过去 30 天)
显示 更早的评论
hey everyone, i ahope someone can help me with this code, what i am trying to do is plotting a fitting line. my graf is shown, but the fit line, is not where it should be, it is the wrong direction, and the wrong angle, please what i am doing wrong ?
this is my code :
for k=50:100
oneRow = binaryImage(k, :);
leftEdge = find(oneRow, 1, 'first');
rightEdge = find(oneRow, 1, 'last');
hold on;
midpoints(k) = (leftEdge + rightEdge)/2;
%plot the left and right edge
plot(leftEdge, k, 'rx','LineWidth',2);
plot(rightEdge, k, 'rx','LineWidth',2);
% CENTER POINTS
plot(midpoints(k), k, 'yx','LineWidth',2);
end
X=[1:100];
new_x = linspace(1, 100);
coeffs = polyfit(X, midpoints, 1);
new_y = polyval(coeffs, new_x);
plot(new_x,new_y, '-','LineWidth',2);
any help will be appreciated thanks.
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!