From: james bejon on
Dear All, Is there a neat way of getting from, say,

[3, 5, 8]

to

[0, 0, 1, 0, 1, 0, 0, 1]?
From: Walter Roberson 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]?

B = false(1,max(A));
B(A) = true;
From: David Young on
x = [3 5 8];
y = zeros(1, max(x));
y(x) = 1
From: David Young on
Oops I didn't look at the subject line, just the example. Walter's answer is the right one, ignore mine.
From: Walter Roberson on
Walter Roberson 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]?
>
> B = false(1,max(A));
> B(A) = true;

Additional note: if there can be big gaps between the true values, then you
may wish to consider using sparse arrays. Sparse arrays are supported for
values of class double, and values of class logical, but (not as yet) for any
other class.