# Thread Subject: function in nlinfit

 Subject: function in nlinfit From: Jan Date: 22 May, 2012 06:44:07 Message: 1 of 2 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 (.*, ./, .^).
 Subject: function in nlinfit From: Torsten Date: 22 May, 2012 07:49:07 Message: 2 of 2 On 22 Mai, 08:44, "Jan " wrote: > 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 > %

### Everyone's Tags:

Separated by commas
Ex.: root locus, bode

### What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.