Cody

Solution 560183

Submitted on 19 Jan 2015 by Alfonso Nieto-Castanon
  • Size: 118
  • This is the leading solution.
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
%% % first some basic tests A = 1; B = sub_double(A); y = B(1); y_correct = 1; assert(isequal(y,y_correct))

2   Pass
%% A = [1 2 3 4 5 6 7 8 9]; B = sub_double(A); y = B([1 3],[3 1]); y_correct = [3 7]; assert(isequal(y,y_correct))

3   Pass
%% A = [1 2 3 4 5 6 7 8 9]; B = sub_double(A); y = B([1 3],[3 end]); y_correct = [3 9]; assert(isequal(y,double(y_correct)))

4   Pass
%% A = [1 2 3 4 5 6 7 8 9]; B = sub_double(A); y = B(1,[3 1]); y_correct = [3 1]; assert(isequal(y,y_correct))

5   Pass
%% A = [1 2 3 4 5 6 7 8 9]; B = sub_double(A); y = B(2:end); y_correct = [4 7 2 5 8 3 6 9]; assert(isequal(y,y_correct))

6   Pass
%% A = magic(5); B = sub_double(A); y = B([1 5 4 3 2],[3 4 5 1 2]); y_correct = [1:5]; assert(isequal(y,y_correct))

7   Pass
%% A = magic(7); B = sub_double(A); rows = randi(7,1,10); cols = randi(7,1,10); y = B(rows,cols); y_correct = arrayfun(@(R,C)A(R,C),rows,cols); assert(isequal(y,y_correct))

8   Pass
%% A = 1; B = sub_double(A); B(1) = 3; A = 3; assert(isequal(A,B))

9   Pass
%% A = [1 2 3 4 5 6 7 8 9]; B = sub_double(A); B([1 2 3],[3 2 1]) = 0; A = [1 2 0 4 0 6 0 8 9]; assert(isequal(A,B))

10   Pass
%% A = [1 2 3 4 5 6 7 8 9]; B = sub_double(A); B([1 3],[3 end]) = [7 7]; A = [1 2 7 4 5 6 7 8 7]; assert(isequal(double(A),double(B)))

11   Pass
%% A = [1 2 3 4 5 6 7 8 9]; B = sub_double(A); y = B(:,:); y_correct = [1 5 9]; assert(isequal(y,y_correct))

12   Pass
%% A = [1 2 3 4 5 6 7 8 9]; B = sub_double(A); B(2:end) = [2:9]; A = A'; assert(isequal(B,A))

13   Pass
%% A = magic(5); B = sub_double(A); B([1 5 4 3 2],[3 4 5 1 2])=0; assert(isequal(sum(~[B B']),ones(1,10)))

14   Pass
%% A = magic(7); B = sub_double(A); rows = randi(7,1,10); cols = randi(7,1,10); vals = randi(7,1,10); B(rows,cols) = vals; for k = 1:10 A(rows(k),cols(k))=vals(k); end assert(isequal(A,B))

More from this Author47