Path: news.mathworks.com!not-for-mail
From: "Jos " <DELjos@jasenDEL.nl>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Split a monotonic array
Date: Mon, 20 Oct 2008 12:30:19 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 28
Message-ID: <gdhtkr$g3c$1@fred.mathworks.com>
References: <gdg54q$3e1$1@fred.mathworks.com>
Reply-To: "Jos " <DELjos@jasenDEL.nl>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1224505819 16492 172.30.248.38 (20 Oct 2008 12:30:19 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 20 Oct 2008 12:30:19 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 870065
Xref: news.mathworks.com comp.soft-sys.matlab:496219

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gdg54q$3e1$1@fred.mathworks.com>...
> I have a strict sorted array such as
> 
> A = [ 8 17 24 29 33 36 39 45 56 64 ]
> 
> I would like to split this array into non-overlapping parts such that: in each part A is bracketed in a interval not larger than a given length said dmax=30.
> 
> So in the above I would have
> 
> A1 = [ 8 17 24 ]
> A2 = [ 29 29 33 36 39 45 ]
> A3 = [ 56 64 ]
> 

Hi Bruno,

here is a one-liner

A = [ 8 17 24 29 33 36 39 45 56 64 ]
dmax = 20 
C = mat2cell(A,1,diff(unique([0 floor(interp1(A,1:numel(A),A(1)+d:d:A(end))) numel(A)])))

Note that A should be monotonic, and the result is a cell array instead of N distinct variables.

hth
Jos