Path: news.mathworks.com!not-for-mail
From: "Pithawat " <tanvach+matlab@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Do stuff without colons
Date: Tue, 9 Dec 2008 21:47:01 +0000 (UTC)
Organization: Univ of Oxford
Lines: 15
Message-ID: <ghmp0l$93e$1@fred.mathworks.com>
References: <ghmkpn$9ml$1@fred.mathworks.com>
Reply-To: "Pithawat " <tanvach+matlab@gmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1228859221 9326 172.30.248.35 (9 Dec 2008 21:47:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 9 Dec 2008 21:47:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 330324
Xref: news.mathworks.com comp.soft-sys.matlab:505969


The closest thing I've come across is colon() function. However, this can only substitute n:m type syntax but not a(n:m).

A subset of this function is really easy to implement:

function out = manipulate(A,B)
out = A(B);

So to solve my original question: manipulate(randperm(100),1:10)

But it doesn't work for things like :

a = randperm(100);
b = a(end/2:end)

I'm sure there must be a function hidden somewhere!