Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: vector operation, selecting chunks
Date: Fri, 20 Mar 2009 17:20:18 +0000 (UTC)
Organization: Battelle Energy Alliance (INL)
Lines: 19
Message-ID: <gq0j8i$if9$1@fred.mathworks.com>
References: <gq0fo1$l89$1@fred.mathworks.com>
Reply-To: <HIDDEN>
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 1237569618 18921 172.30.248.38 (20 Mar 2009 17:20:18 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 20 Mar 2009 17:20:18 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 688530
Xref: news.mathworks.com comp.soft-sys.matlab:526472


One approach using old-school vectorization:


% Some data:
v=round(rand(100,1)*9);
M=[1,4;7,8;80,93];

% The engine:
L = size(M,1);
R = cumsum(M(:,2)-M(:,1)+1);
IDX = ones(1,R(end));
IDX(1) = M(1,1);
IDX(1 + R(1:end-1)) = M(2:L,1) - M(1:L-1,2);
v2 = v(cumsum(IDX));




uujj$_ed^|aW0eYW[[OuukuCXj[fue_f6[k^du]WXucYWelec^;WbeoWbW|