|
Hi
i am trying to compute a cylinder from a Point Cloud. I approximated starting Values and with them i want to use nlinfit to get my 7 parameters for a cylinder( x,y,z for 1 Point on the axis, x,y,z for axis direction and the radius ).
I wrote following function :
function [ Mx,My,Mz,ax,ay,az,r,resi ] = computeCylinder(X, Mx0,My0,Mz0, ax0,ay0,az0,r0 )
%COMPUTECYLINDER Summary of this function goes here
% Detailed explanation goes here
y = zeros(length(X),1);
cyl = @(a,x)((a(2)*(a(6)-x(3))-a(3)*(a(5)-x(2)))^2
+ (a(3)*(a(4)-x(1))-a(1)*(a(6)-x(3)))^2
+ (a(1)*(a(5)-x(2))-a(2)*(a(4)-x(1)))^2
- a(7)*sqrt((a(1))^2+(a(2))^2+(a(3))^2));
a0 = [Mx0,My0,Mz0,ax0,ay0,az0,r0];
[aComp, resi] = nlinfit(X,y,cyl,a0);
Mx= aComp(4);
My= aComp(5);
Mz= aComp(6);
ax= aComp(1);
ay= aComp(2);
az= aComp(3);
r = aComp(7);
end
X is my PointCloud ( dimension is 115568x3). The other input Parameters are the starting values.
When i run this function i get the following error :
Error using nlinfit (line 126)
MODELFUN must be a function that returns a vector of fitted values the same size as Y (115568-by-1). The model
function you provided returned a result that was 1-by-1.
One common reason for a size mismatch is using matrix operators (*, /, ^) in your function instead of the
corresponding elementwise operators (.*, ./, .^).
|