Cody

Problem 1203. Reference Index Number

Solution 3199011

Submitted on 13 Oct 2020 by ivan fernandez
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 indici = [] indici = 3 indici = 3 5 indici = 3 5 4 indici = 3 5 4 5 K = 3 5 4 5

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

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

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

indici = [] indici = 1 indici = 1 4 indici = 1 4 7 indici = 1 4 7 10 indici = 1 4 7 10 13 indici = 1 4 7 10 13 16 indici = 1 4 7 10 13 16 19 indici = 1 4 7 10 13 16 19 22 indici = 1 4 7 10 13 16 19 22 25 K = 1 4 7 10 13 16 19 22 25

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 indici = [] indici = 3 indici = 3 3 indici = 3 3 3 K = 3 3 3

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'} indici = [] R = 1×4 string array "a" "b" "c" "d" V = 1×3 string array "b" "a" "d" indici = 2 indici = 2 1 indici = 2 1 4 K = 2 1 4

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'} indici = [] R = 1×9 string array "one" "two" "three" "red" "yellow" "blue" "dog" "cat" "fish" V = 1×8 string array "one" "fish" "two" "fish" "red" "fish" "blue" "fish" indici = 1 indici = 1 9 indici = 1 9 2 indici = 1 9 2 9 indici = 1 9 2 9 4 indici = 1 9 2 9 4 9 indici = 1 9 2 9 4 9 6 indici = 1 9 2 9 4 9 6 9 K = 1 9 2 9 4 9 6 9

Suggested Problems

More from this Author11

Community Treasure Hunt

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

Start Hunting!