From: Jos (10584) on
etgil <etienne.giroux.leveille(a)gmail.com> wrote in message <88985670.175435.1274119707603.JavaMail.root(a)gallium.mathforum.org>...
> 2 vectors
> x=[a b c a b c a b c a b c....]
> y=unique(x).... so (a b c).
>
> trying to index x so that i have a matrix that would look something like this. the resulting matrix is of size numel(x) by numel(y)
>
> a b c
> 0 1 0
> 0 1 0
> 0 0 1
> 1 0 0

Something like this:

X = [1 2 3 2 3 1 1 2 3 3]

unX = unique(X) % unique elements of X in order
TF = bsxfun(@eq, X.', unX) % the desired (logical) matrix

hth
Jos
From: etgil on
thanks,
It works very well.

Any idea of how I could do if I wanted a 3D index of 1 and 0.
From: Walter Roberson on
etgil wrote:
> thanks,
> It works very well.
>
> Any idea of how I could do if I wanted a 3D index of 1 and 0.

I think I would need more information about what the input would look like in
that case, and about what you want the output to look like.
First  |  Prev  | 
Pages: 1 2
Prev: Rearrange my Matrix
Next: Rearrange my Matrix