From: etgil on
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
From: Walter Roberson on
etgil wrote:
> 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

[y,I,J] = unique(x);
T = zeros(length(J),length(y), 'logical');
T(sub2ind(size(T), 1:length(J), J)) = true;
From: Nathan on
On May 17, 11:07 am, etgil <etienne.giroux.levei...(a)gmail.com> wrote:
> 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

What exactly are you trying to do?

I can't make sense of what you just posted.

Apparently, from the subject line, you want to do something without
loops.
You want to create some matrix of size numel(x) by numel(y).

The sample matrix that you provided doesn't make sense. Already, the
matrix is not of size numel(x) by numel(y), as numel(x) is at least 12
(not including the dots), while the dimensions of the provided matrix
are 5x3 (including the a b c)...

Can you give an actual example of what you are trying to do with some
sample data instead of these mysterious variables/values of "a" "b"
and "c"?

-Nathan
From: etgil on
Thanks,

This is very close to what I need.

It doesn't seem to handle the 'logical' part very well.
From: Walter Roberson on
etgil wrote:

> This is very close to what I need.
>
> It doesn't seem to handle the 'logical' part very well.

That part isn't important. You can leave out the 'logical' in the zeros()
call, and change the true to 1. The only difference will be in the amount of
storage used, and whether you can directly use the result as a logical index
or not.
 |  Next  |  Last
Pages: 1 2
Prev: Rearrange my Matrix
Next: Rearrange my Matrix