Cody

# Problem 1203. Reference Index Number

Solution 1219904

Submitted on 26 Jun 2017 by Augusto Mazzei
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
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 V = 1×4 cell array [7] [5] [6] [5] R = 1×5 cell array [9] [8] [7] [6] [5] ok ok ok ok

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

R = 1 2 3 4 5 6 7 8 9 10 V = 0×0 empty cell array R = 1×10 cell array [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

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

V = 1×9 cell array [-1.6310] [-1.2079] [-0.8523] [-0.5532] [0.0663] [0.5268] [0.6617] [0.9969] [2.2555] R = 25×1 cell array [-1.6310] [-1.3665] [-1.2388] [-1.2079] [-0.9756] [-0.8552] [-0.8523] [-0.6809] [-0.5678] [-0.5532] [-0.3297] [-0.2047] [ 0.0663] [ 0.3095] [ 0.4283] [ 0.5268] [ 0.5656] [ 0.6365] [ 0.6617] [ 0.8260] [ 0.9658] [ 0.9969] [ 1.1890] [ 1.4606] [ 2.2555] ok ok ok ok ok ok ok ok ok

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

R = -2 -1 0 1 2 V = 1×3 cell array [0] [0] [0] R = 1×5 cell array [-2] [-1] [0] [1] [2] ok ok ok

5   Pass
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' ok ok ok

6   Pass
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' ok ok ok ok ok ok ok ok

### Community Treasure Hunt

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

Start Hunting!