Cody

# Problem 44496. vector indexes for a matrix

Solution 2078766

Submitted on 4 Jan 2020 by Asif Newaz
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
M = [1 2 3; 4 5 6; 7 8 9]; P = [1 2 3]; Q= [1 2 3]; y_correct = [1,5,9]; assert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))

a = 1 5 9 y = 1 5 9

2   Pass
M = [2 5 8; 3 6 9; 4 7 10]; P = [1 3 2]; Q = [1 1 2]; y_correct = [2,4,6]; assert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))

a = 1 3 5 y = 2 4 6

3   Pass
M = [1 5 4; 7 9 6; 8 2 3]; P = 1:3; Q = 3:-1:1; y_correct = [4,9,8]; assert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))

a = 7 5 3 y = 4 9 8

4   Pass
M = [1 5 4; 7 9 6; 8 2 3]; P = reshape(repmat((1:3)',[1,3]),[1,9]); Q = reshape(repmat(1:3,[3,1]),[1,9]); y_correct = M(:)'; assert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))

a = 1 2 3 4 5 6 7 8 9 y = 1 7 8 5 9 2 4 6 3

5   Pass
M = [1 5 4 2; 7 9 6 1; 8 2 3 5]; P = [2,1,3,2]; Q = 1:4; y_correct = [7,5,3,1]; assert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))

a = 2 4 9 11 y = 7 5 3 1

### Community Treasure Hunt

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

Start Hunting!