Cody

# Problem 1203. Reference Index Number

Solution 2096544

Submitted on 17 Jan 2020
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   Fail
R = 9:-1:5 V = [7 5 6 5]; K = [3 5 4 5]; assert(isequal(refIndex(R,V),K))

R = 9 8 7 6 5

Index exceeds the number of array elements (5). Error in refIndex (line 2) K = R(V) Error in Test1 (line 4) assert(isequal(refIndex(R,V),K))

2   Pass
R = 1:10 V = []; K = []; assert(isequal(refIndex(R,V),K))

R = 1 2 3 4 5 6 7 8 9 10 K = []

3   Fail
R = unique(randn(5)); V = R(1:3:end)'; K = 1:3:numel(R); assert(isequal(refIndex(R,V),K))

Array indices must be positive integers or logical values. Error in refIndex (line 2) K = R(V) Error in Test3 (line 4) assert(isequal(refIndex(R,V),K))

4   Fail
R = -2:2 V = [0 0 0]; K = [3 3 3]; assert(isequal(refIndex(R,V),K))

R = -2 -1 0 1 2

Array indices must be positive integers or logical values. Error in refIndex (line 2) K = R(V) Error in Test4 (line 4) assert(isequal(refIndex(R,V),K))

5   Fail
R = {'a' 'b' 'c' 'd'} V = {'b' 'a' 'd'}; K = [2 1 4]; assert(isequal(refIndex(R,V),K))

R = 1×4 cell array {'a'} {'b'} {'c'} {'d'}

Unable to use a value of type cell as an index. Error in refIndex (line 2) K = R(V) Error in Test5 (line 4) assert(isequal(refIndex(R,V),K))

6   Fail
R = {'one' 'two' 'three' 'red' 'yellow' 'blue' 'dog' 'cat' 'fish'} V = {'one' 'fish' 'two' 'fish' 'red' 'fish' 'blue' 'fish'}; K = [1 9 2 9 4 9 6 9]; assert(isequal(refIndex(R,V),K))

R = 1×9 cell array {'one'} {'two'} {'three'} {'red'} {'yellow'} {'blue'} {'dog'} {'cat'} {'fish'}

Unable to use a value of type cell as an index. Error in refIndex (line 2) K = R(V) Error in Test6 (line 4) assert(isequal(refIndex(R,V),K))