Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 352810

Submitted on 16 Nov 2013

Incorrect

0Size
Leading solution size is 300.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
feval(@assignin,'caller','score',0);

                    
2
Pass
 
%%
%urlwrite('http://tinyurl.com/matlab-Knots','Knots_sample.mat')
urlwrite('http://rmatlabtest.appspot.com/testsuite_sample_knots.mat','Knots_sample.mat');

                    
3
Fail
 
%%
eKnots=[94 50 1719 11390 18 3446 7402 669 2558 13557 5376 25025 122 11566 2560 15726 7569 11728 35178 1872 972 29917 7433 2013 3 3081 1381 1424 1102 3534 2849 14520 16892 16553 18887 245 5729 3256 400 24811 290 15081 5679 12310 262 16317 1614 249 8782 192];
cases=4;
nKnots=zeros(cases,1);
KnotTime=zeros(cases,1);
rclock=clock;
rng(floor(rclock(6)*1000),'twister'); % Seed the random function
tKnots=randi(50,cases,1); % anti-code answer
load Knots_sample.mat
testsuite=suite; % update
for n=1:cases
 a=testsuite(tKnots(n)).a;
 xy=testsuite(tKnots(n)).xyIn;
 time0 = cputime;
  nKnots(n)=Knots(a,xy);
 KnotTime(n) = cputime - time0;
end
for n=1:cases
 assert(isequal(nKnots(n),eKnots(tKnots(n))),sprintf('Knot %i Was %i Expected %i',tKnots(n),nKnots(n),eKnots(tKnots(n))));
end
% Success: Report Times
P=[tKnots nKnots KnotTime]';
fprintf('Knot %i  Knots %i  Time %10.6f\n',P);
Error: Knot 7 Was 7383 Expected 7402
4
Fail
 
%%
% Run for Time Score uses Knots [3 6 15 18 24 30 37 42 46 49]
eKnots=[94 50 1719 11390 18 3446 7402 669 2558 13557 5376 25025 122 11566 2560 15726 7569 11728 35178 1872 972 29917 7433 2013 3 3081 1381 1424 1102 3534 2849 14520 16892 16553 18887 245 5729 3256 400 24811 290 15081 5679 12310 262 16317 1614 249 8782 192];
cases=10;
nKnots=zeros(cases,1);
KnotTime=zeros(cases,1);
rclock=clock;
rng(floor(rclock(6)*1000),'twister'); % Seed the random function
%tKnots=randi(50,cases,1);
load Knots_sample.mat
testsuite=suite; % update
tKnots=[3 6 15 18 24 30 37 42 46 49]';
for n=1:cases
 a=testsuite(tKnots(n)).a;
 xy=testsuite(tKnots(n)).xyIn;
 time0 = cputime;
  nKnots(n)=Knots(a,xy);
 KnotTime(n) = cputime - time0;
end
for n=1:cases
 assert(isequal(nKnots(n),eKnots(tKnots(n))),sprintf('Knot %i Was %i Expected %i',tKnots(n),nKnots(n),eKnots(tKnots(n))));
end
% Success: Report Times
P=[tKnots nKnots KnotTime]';
fprintf('Knot %i  Knots %i  Time %10.6f\n',P);
% Score in msec
feval(@assignin,'caller','score',min(10000,floor(1000*sum(KnotTime))));
Error: Knot 3 Was 1716 Expected 1719