Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: fitting curve at polar coordinate Date: Mon, 23 Apr 2012 00:26:06 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 24 Message-ID: <jn27iu$h0$1@newscl01ah.mathworks.com> References: <jigqp3$f6e$1@newscl01ah.mathworks.com> <jki2uc$ocm$1@newscl01ah.mathworks.com> <jn22c5$bab$1@newscl01ah.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-02-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1335140766 544 172.30.248.47 (23 Apr 2012 00:26:06 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Mon, 23 Apr 2012 00:26:06 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:765538 "M Srj" wrote in message <jn22c5$bab$1@newscl01ah.mathworks.com>... > Thanks Michael for your reply. I run this m-file but got error messages in MATLAB after my data in (theta, R) format: > ....... > Error using / > Matrix dimensions must agree. > Error in fit (line 4) > R=a/(1 + b* cos(theta*pi/180)); > ...... > "Michael W." wrote in message <jki2uc$ocm$1@newscl01ah.mathworks.com>... > > function R = fit(theta, param) > > a = param(1); > > b = param(2); > > R=a/(1 + b cos(theta); > > end - - - - - - - - - - The function you pass to 'lsqcurvefit' should have the parameters as its first, not its second, argument: R = fit(param,theta). Also unless I am greatly mistaken, 'lsqcurvefit' passes 'fit' a vector of theta values, in which case you should have: R=a./(1 + b cos(theta); with the "./" kind of division in the 'fit' definition. The curve you are trying to fit your data to is an ellipse, so as an alternative you might want to check out some of the numerous threads in this newsgroup that have dealt with fitting ellipses. You might get a far better fit that way. Roger Stafford