Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 190865

Submitted on 14 Jan 2013

Incorrect

33Size
Leading solution size is 16.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
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
2
Fail
 
%%
R = 1:10
V = [];
K = [];
assert(isequal(refIndex(R,V),K))
Error: Output argument "K" (and maybe others) not assigned during call to "/users/msssystem1/refIndex.m>refIndex".
3
Pass
 
%%
R = unique(randn(5));
V = R(1:3:end)';
K = 1:3:numel(R);
assert(isequal(refIndex(R,V),K))

                    
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
5
Fail
 
%%
R = {'a' 'b' 'c' 'd'}
V = {'b' 'a' 'd'};
K = [2 1 4];
assert(isequal(refIndex(R,V),K))
Error: Undefined function 'eq' for input arguments of type 'cell'.
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))
Error: Undefined function 'eq' for input arguments of type 'cell'.