Path: news.mathworks.com!newsfeed-00.mathworks.com!news.kjsl.com!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!rt.uk.eu.org!aioe.org!.POSTED!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: consecutive numbers
Date: Sat, 06 Jul 2013 22:01:46 -0500
Organization: Aioe.org NNTP Server
Lines: 32
Message-ID: <kralmo$eeo$1@speranza.aioe.org>
References: <kr6gus$b8d$1@newscl01ah.mathworks.com> <kr9t63$mk1$1@speranza.aioe.org> <kra0lq$vhu$1@speranza.aioe.org> <krag96$69f$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: 6z92ouJs6jUrQzBaNtLMgA.user.speranza.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.28) Gecko/20120306 Thunderbird/3.1.20
X-Notice: Filtered by postfilter v. 0.8.2
Xref: news.mathworks.com comp.soft-sys.matlab:798934

On 7/6/2013 8:29 PM, fmri wrote:
...

>> > >> x= [1 2 3 7 8 9 10 13 14 20 21 22 23 24 ];
>> > >> s=splitvec(d,'value'); % Bruno's SplitVec @ FEX
>> ...
...
>> OTOH the following should work for any vector for consecutive values...
>>
>> >> cnts=cellfun(@length,s(cellfun(@(x) all(x==1),s)))+1;
>> >> res=arrayfun(@(x,y) (repmat(y,1,x)), cnts,(1:length(cnts)) ...
>> ,'uniformoutput',false);
>> >> res=[res{:}]
...

> Hi dpb,
> thanks for this. Honestly, I was facing some problems while applying yr
> commands. I am still learning the basic functions and always get
> confused when I see cellfun and arrayfun ...

I'm still learning them meself having only had a release that contains 
them <1 yr and not actively doing any technical work (my day job is 
farming now).  So, when I thought about the length vectors as a way I 
took it as a challenge to use it... :)

BTW, it would be a little cleaner to get the final result above as

res=cell2mat(arrayfun(@(x,y) (repmat(y,1,x)), cnts,(1:length(cnts)), ...
                              'uniformoutput',false));

--