f



problem with matlab compile error in matlab6.5 work in matlab 7, help!

hi to all,

i have a problem running this code on Matlab 6.5, it running fine on matlab Version 7.1.0.183 (R14) Service Pack 3 (but i have not this version) 

Matlab 6.5 give me a compilation error: 

?? Error: File: C:\Documents and Settings\Roby\Documenti\Tesi\portoni_sd_sa\portoni_sd_sa\portoni_2d.m Line: 23 Column: 19 
"identifier" expected, "(" found. 
row 23 col 19 start from @(points) ... 
(at line begining with error_function = ) 

Can u help me to resolve this error? can u give me sugestion how can write this line
i'm a beginner and i can't understand why this error happens
u can find the line here, this is the code:


clear all 

% define 3 peers in a 2-dim space 
% every row is a peer 

peers = [ 4 7 ; 2 12 ; 5 5 ]; 

pings = zeros(3,3); 
for peer_column = 2:(size(peers, 1)) 
for peer_row = 1:(peer_column - 1) 
distance = sqrt( ... 
(peers(peer_column, 1) - peers(peer_row, 1))^2 + ... 
(peers(peer_column, 2) - peers(peer_row, 2))^2 ); 
pings(peer_row, peer_column) = distance; 
pings(peer_column, peer_row) = distance; 
end 
end 

% p1 = [0 0] 
% p2 = [points(1) points(2)] 
% p3 = [points(3) points(4)] 

#compile error at this line:
error_function = @(points) ... 

(sqrt(points(1)^2 + points(2)^2) - pings(1, 2))^2 + ... 
(sqrt(points(3)^2 + points(4)^2) - pings(1, 3))^2 + ... 
(sqrt((points(1)-points(3))^2 + (points(2)-points(4))^2) - pings(2, 3))^2; 

% minimize error_function 
% starting points: 
% p2 = [pings(1, 2) 0] 
% p3 = [0 pings(1, 3)] 
points_starting = [pings(1, 2) 0 0 pings(1, 3)]; 
[points, error] = fminsearch(error_function, points_starting); 

%prints results 
pings 
points 
error 


Thank u!
Roby
0
2/18/2009 7:48:02 AM
comp.soft-sys.matlab 211266 articles. 23 followers. lunamoonmoon (257) is leader. Post Follow

1 Replies
1039 Views

Similar Articles

[PageSpeed] 19

"Roberto " <ytrewq2002@libero.it> wrote in message 
news:gngefi$hdv$1@fred.mathworks.com...
> hi to all,
>
> i have a problem running this code on Matlab 6.5, it running fine on 
> matlab Version 7.1.0.183 (R14) Service Pack 3 (but i have not this 
> version)

*snip*

Did you read the response I posted in the thread you created for this exact 
same question yesterday?

http://www.mathworks.com/matlabcentral/newsreader/view_thread/244729#628940

Best practice in newsgroups is that if you're discussing the same issue, 
keep it in the same thread rather than starting a new one to talk about the 
same issue.

The easiest way to correct this problem is to rewrite the anonymous function 
as a subfunction.  You will need to pass an additional parameter containing 
the array pings into the subfunction; see Q4.13 in the newsgroup FAQ for 
more information on how to do that.

-- 
Steve Lord
slord@mathworks.com 


0
slord (13689)
2/18/2009 3:05:38 PM
Reply: