Problem 2393. Measure a Special Distance

Solution 465749

Submitted on 3 Jul 2014 by Selvaraaju Murugesan
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
%% cd=randi(100); gd=-randi(100); linef=(cd-gd)*rand(randi([50,100]),2)+gd; % n=size(linef,1); ldist=zeros(n); for a=1:n for b=1:n if linef(a,1)>0&&linef(b,2)>0 ldist(b,a)=(linef(a,1)+linef(b,2)-cd).^2; elseif linef(a,1)<0&&linef(b,2)<0 ldist(b,a)=(linef(a,1)+linef(b,2)-gd).^2; else ldist(b,a)=(abs(linef(a,1)-linef(b,2))-(cd-gd)).^2; end end end y_correct=ldist; f_result=measure_dist(linef,cd,gd); assert(all(abs(f_result(:)-y_correct(:))<0.1))

Suggested Problems

Community Treasure Hunt

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

Start Hunting!