From: Walter Roberson on
Oleg Komarov wrote:

>> So now who is going to give us an answer in terms of
>> logical(accumarray(...)) ? ;-)
>
> Out = accumarray(A.',true,[],@logical);
>
> Another versione :). Only if unique(A) == A.

Out = logical(accumarray(A.', 1));

This version does not require unique(A) == A.

I am not at all experienced in accumarray, but looking at the
documentation, it appears to me that your version would also work with
repeated elements if you changed the @logical to @any .
From: dpb on
us wrote:
> dpb
>> > l = any(bsxfun(@eq,1:max(x),x.'));
>> Chuckle...
>
> this is NOT funny - ...

Not even a snicker??? :)

--
From: james bejon on
There's some really neat stuff here. Thanks so much. I'm very new to Matlab, but am starting to see how concise its code can be. On a related note, Can anyone think of a neat way of converting, say,

[3, 8, 12]

to

[1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3]?

Or better still:

[3, 8, 12;
3, 7, 12]

to

[1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3;
1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3]?
From: Oleg Komarov on
Walter Roberson <roberson(a)hushmail.com> wrote in message <houedm$r10$1(a)canopus.cc.umanitoba.ca>...
> Oleg Komarov wrote:
>
> >> So now who is going to give us an answer in terms of
> >> logical(accumarray(...)) ? ;-)
> >
> > Out = accumarray(A.',true,[],@logical);
> >
> > Another versione :). Only if unique(A) == A.
>
> Out = logical(accumarray(A.', 1));
>
> This version does not require unique(A) == A.
>
> I am not at all experienced in accumarray, but looking at the
> documentation, it appears to me that your version would also work with
> repeated elements if you changed the @logical to @any .

You're right!

Oleg
From: Oleg Komarov on
"james bejon"
> There's some really neat stuff here. Thanks so much. I'm very new to Matlab, but am starting to see how concise its code can be. On a related note, Can anyone think of a neat way of converting, say,
>
> [3, 8, 12]
>
> to
>
> [1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3]?
>
> Or better still:
>
> [3, 8, 12;
> 3, 7, 12]
>
> to
>
> [1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3;
> 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3]?

Be rude!

A = [3,8,12];
rude(A./(1:numel(A)), 1:numel(A)) % FEX by us

Oleg