Cody

# Problem 2836. Modify subscripts - easier

Solution 2971456

Submitted on 20 Sep 2020 by Rafael S.T. Vieira
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,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))

### Community Treasure Hunt

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

Start Hunting!