From: dpb on
james bejon wrote:
> Dear All, Is there a neat way of getting from, say,
>
> [3, 5, 8]
>
> to
>
> [0, 0, 1, 0, 1, 0, 0, 1]?

Alternately,

o(x)=1; % create the 0/1 vector
l = logical(o); % turn it into a logical one

Too bad for things like this ML doesn't support nested assignment..

l = logical(o(x)=1); % Doesn't work, of course... :(

--

From: Nathan on
On Mar 30, 2:37 pm, dpb <n...(a)non.net> wrote:
> james bejon wrote:
> > Dear All,  Is there a neat way of getting from, say,
>
> > [3, 5, 8]
>
> > to
>
> > [0, 0, 1, 0, 1, 0, 0, 1]?
>
> Alternately,
>
> o(x)=1;          % create the 0/1 vector
> l = logical(o);  % turn it into a logical one
>
> Too bad for things like this ML doesn't support nested assignment..
>
> l = logical(o(x)=1);   % Doesn't work, of course... :(
>
> --

If you were going to do that, why not just make it logical in the
first place?

o(x) = true;

-Nathan
From: dpb on
Nathan wrote:
....

> If you were going to do that, why not just make it logical in the
> first place?
>
> o(x) = true;

Primarily because...

>> which true
true not found.
>> help true

true.m not found.

>>

:(

--
From: Walter Roberson on
dpb wrote:
> james bejon wrote:
>> Dear All, Is there a neat way of getting from, say,
>>
>> [3, 5, 8]
>>
>> to
>>
>> [0, 0, 1, 0, 1, 0, 0, 1]?
>
> Alternately,
>
> o(x)=1; % create the 0/1 vector
> l = logical(o); % turn it into a logical one
>
> Too bad for things like this ML doesn't support nested assignment..
>
> l = logical(o(x)=1); % Doesn't work, of course... :(

Well, if you are going to be like that!

l = any(bsxfun(@eq,1:max(x),x.'));
From: james bejon on
Thanks for all the really helpful replies!

I'm currently toying with the (perhaps hungry?) expression:

ismember((1:A(end)), A)

(I can assume A is in ascending order)