Cody

# Problem 1134. Get ranks of values in a vector

Solution 189536

Submitted on 11 Jan 2013 by James
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
%% x = 0:9; y_correct = 1:10; assert(isequal(getrank(x),y_correct))

y = 1 0 0 0 0 0 0 0 0 0 z = 1 y = 1 2 0 0 0 0 0 0 0 0 z = 1 2 y = 1 2 3 0 0 0 0 0 0 0 z = 1 2 3 y = 1 2 3 4 0 0 0 0 0 0 z = 1 2 3 4 y = 1 2 3 4 5 0 0 0 0 0 z = 1 2 3 4 5 y = 1 2 3 4 5 6 0 0 0 0 z = 1 2 3 4 5 6 y = 1 2 3 4 5 6 7 0 0 0 z = 1 2 3 4 5 6 7 y = 1 2 3 4 5 6 7 8 0 0 z = 1 2 3 4 5 6 7 8 y = 1 2 3 4 5 6 7 8 9 0 z = 1 2 3 4 5 6 7 8 9 y = 1 2 3 4 5 6 7 8 9 10 z = 1 2 3 4 5 6 7 8 9 10

2   Pass
%% x = 9:-1:0; y_correct = 10:-1:1; assert(isequal(getrank(x),y_correct))

y = 10 0 0 0 0 0 0 0 0 0 z = 10 y = 10 9 0 0 0 0 0 0 0 0 z = 10 9 y = 10 9 8 0 0 0 0 0 0 0 z = 10 9 8 y = 10 9 8 7 0 0 0 0 0 0 z = 10 9 8 7 y = 10 9 8 7 6 0 0 0 0 0 z = 10 9 8 7 6 y = 10 9 8 7 6 5 0 0 0 0 z = 10 9 8 7 6 5 y = 10 9 8 7 6 5 4 0 0 0 z = 10 9 8 7 6 5 4 y = 10 9 8 7 6 5 4 3 0 0 z = 10 9 8 7 6 5 4 3 y = 10 9 8 7 6 5 4 3 2 0 z = 10 9 8 7 6 5 4 3 2 y = 10 9 8 7 6 5 4 3 2 1 z = 10 9 8 7 6 5 4 3 2 1

3   Pass
%% x = [.5 .8 .1 .9 .7]; y_correct = [2 4 1 5 3]; assert(isequal(getrank(x),y_correct))

y = 2 0 0 0 0 z = 2 y = 2 4 0 0 0 z = 2 4 y = 2 4 1 0 0 z = 2 4 1 y = 2 4 1 5 0 z = 2 4 1 5 y = 2 4 1 5 3 z = 2 4 1 5 3

4   Pass
%% x = [2 -1 7 -6 3 2]; y_correct = [3 2 6 1 5 4] ; assert(isequal(getrank(x),y_correct))

y = 3 0 0 0 0 0 z = 3 y = 3 2 0 0 0 0 z = 3 2 y = 3 2 6 0 0 0 z = 3 2 6 y = 3 2 6 1 0 0 z = 3 2 6 1 y = 3 2 6 1 5 0 z = 3 2 6 1 5 y = 3 2 6 1 5 3 z = 3 2 6 1 5 3