I have some difficulties programming a function in MATLAB. I want to construct a function that converts a given ranking into a binary choice matrix. For example, when 3 options are ranked in a ranking R(3,1,2) the binary choice matrix should be
[0 1 0;
0 0 0;
1 1 0]
So when element i
proceeds element j
, the matrix element a(i,j)
is 1
and 0
otherwise. Could anyone help me create this function please?
I'm not sure I understand the question, but this seems to do what you want:
r = [3 1 2]; %// ranking
[~, s] = sort(r);
M = bsxfun(@gt, s, s.');