lsqnonlin function error confusion

1 view (last 30 days)
Robert Smith
Robert Smith on 20 Sep 2017
Commented: Robert Smith on 20 Sep 2017
Hi, I was running this code and it was working well but when I made small modifications it stopped working. Any help or clarification is appreciated! See code and error below:
function [R] = optimize_radius (raw_EM_cath)
numcath = size(raw_EM_cath,2);
for i = 1:numcath
raw_EM_cath(i).cath = raw_EM_cath(i).cath(8:end,:);
center = lsqnonlin(@(point)distance(point, raw_EM_cath(i).cath), [median(raw_EM_cath(i).cath(:,1)), median(raw_EM_cath(i).cath(:,2)), median(raw_EM_cath(i).cath(:,3))]);
d = pdist2(center, raw_EM_cath(i).cath);
R(i, :) = [ mean(d), std(d), median(d), mode(d) ];
end
end
ERROR:
Output argument "d" (and maybe others) not assigned during call to
"optimize_radius>distance".
Error in optimize_radius>@(point)distance(point,raw_EM_cath(i).cath) (line 12)
center = lsqnonlin(@(point)distance(point, raw_EM_cath(i).cath),
[median(raw_EM_cath(i).cath(:,1)), median(raw_EM_cath(i).cath(:,2)),
median(raw_EM_cath(i).cath(:,3))]);
Error in lsqnonlin (line 196)
initVals.F = feval(funfcn{3},xCurrent,varargin{:});
Error in optimize_radius (line 12)
center = lsqnonlin(@(point)distance(point, raw_EM_cath(i).cath),
[median(raw_EM_cath(i).cath(:,1)), median(raw_EM_cath(i).cath(:,2)),
median(raw_EM_cath(i).cath(:,3))]);
Caused by:
Failure in initial objective function evaluation. LSQNONLIN cannot continue.
  4 Comments
Walter Roberson
Walter Roberson on 20 Sep 2017
There should not be a space between the dash and the "all". Not
which - all distance
But
which -all distance
Robert Smith
Robert Smith on 20 Sep 2017
Oh, forgive me. Here is the output:
distance is a Java method % java.awt.Point method distance is a Java method % java.awt.geom.Point2D method

Sign in to comment.

Answers (0)

Categories

Find more on Just for fun in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!