[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: building dynamic ranges from matrix
From: |
Juan Pablo Carbajal |
Subject: |
Re: building dynamic ranges from matrix |
Date: |
Wed, 22 Nov 2017 10:59:33 +0100 |
On Wed, Nov 22, 2017 at 10:57 AM, Juan Pablo Carbajal
<address@hidden> wrote:
> On Wed, Nov 22, 2017 at 10:48 AM, Juan Pablo Carbajal
> <address@hidden> wrote:
>> Hi,
>>
>> If you want to save memory (wouldn't be my main concern, though) you
>> cannot vectorize this easily because the result of each row doesn't
>> have the same size. So arrayfun or cellfun might be your only option
>> (I feel there might be a solution using accumarray, haven't give a
>> thought to it, though).
>>
>> If you do not care wasting memory for values that will be discarted,
>> then do the following (this is reasonable if you know that the gap
>> between the intervals is not huge)
>>
>> M is your Nx2 matrix
>>
>> x = min (M(:)):max (M(:));
>> tf = x >= M(:,1) & x <= M(:,2);
>> tf = or (tf(1,:),tf(2,:));
>> x(tf)
>
> Error: here should be
> tf = or (mat2cell (tf,ones(N,1),size(tf,2)){:})
>
> Also notice that this makes the union of all the intervals, so it
> doesn't repeat indexes. It might not be what you are looking for, but
> maybe you ca improve from here.
and with this correction the results seems to indicate arrayfun is the
way to go :D
Elapsed time is vec:0.207450 fun:0.103145 seconds.
- building dynamic ranges from matrix, AG, 2017/11/21
- Re: building dynamic ranges from matrix, Anthony Gumbs, 2017/11/21
- Re: building dynamic ranges from matrix, Doug Stewart, 2017/11/21
- Re: building dynamic ranges from matrix, AG, 2017/11/21
- Re: building dynamic ranges from matrix, avlas, 2017/11/21
- Re: building dynamic ranges from matrix, avlas, 2017/11/21
- Re: building dynamic ranges from matrix, Juan Pablo Carbajal, 2017/11/22
- Re: building dynamic ranges from matrix, Juan Pablo Carbajal, 2017/11/22
- Re: building dynamic ranges from matrix,
Juan Pablo Carbajal <=
- Re: building dynamic ranges from matrix, AG, 2017/11/27
Re: building dynamic ranges from matrix, avlas, 2017/11/21
Re: building dynamic ranges from matrix, Salva Ardid, 2017/11/21
Re: building dynamic ranges from matrix, Kire Pudsje, 2017/11/27