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 226068

Submitted on 1 Apr 2013 by andrea84

Correct

43Size
Leading solution size is 12.
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
 
%%
N = [1 3 2 7];
IDX= [2 3 4 6];
y_correct = [0 1 3 2 0 7];
assert(isequal(reindex_a_vector(N,IDX),y_correct))
n =
     0     1
n =
     0     1     3
n =
     0     1     3     2
n =
     0     1     3     2     0     7
r =
     1
c =
     4
2
Pass
 
%%
N=[ -1 0 4 2];
IDX=[3 8 1 6];
y_correct = [4 0 -1 0 0 2 0 0];
assert(isequal(reindex_a_vector(N,IDX),y_correct))
n =
     0     0    -1
n =
     0     0    -1     0     0     0     0     0
n =
     4     0    -1     0     0     0     0     0
n =
     4     0    -1     0     0     2     0     0
r =
     1
c =
     4
3
Pass
 
%%
N=[-1 0 4 2]';
IDX=[3 8 1 6];
y_correct = [4 0 -1 0 0 2 0 0]';
assert(isequal(reindex_a_vector(N,IDX),y_correct))
n =
     0     0    -1
n =
     0     0    -1     0     0     0     0     0
n =
     4     0    -1     0     0     0     0     0
n =
     4     0    -1     0     0     2     0     0
r =
     4
c =
     1
n =
     4
     0
    -1
     0
     0
     2
     0
     0
4
Pass
 
%%
N=[1 2 3 4 5 6 7 8 9 10];
IDX=[3 4 5 6 7 8 9 10 11 13];
y_correct=[0 0 1 2 3 4 5 6 7 8 9 0 10];
assert(isequal(reindex_a_vector(N,IDX),y_correct))
n =
     0     0     1
n =
     0     0     1     2
n =
     0     0     1     2     3
n =
     0     0     1     2     3     4
n =
     0     0     1     2     3     4     5
n =
     0     0     1     2     3     4     5     6
n =
     0     0     1     2     3     4     5     6     7
n =
     0     0     1     2     3     4     5     6     7     8
n =
     0     0     1     2     3     4     5     6     7     8     9
n =
     0     0     1     2     3     4     5     6     7     8     9     0    10
r =
     1
c =
    10