Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Clever way to access matrix indices EXCEPTING certain values?
Date: Fri, 21 Dec 2007 20:36:54 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 36
Message-ID: <fkh856$hj9$1@fred.mathworks.com>
References: <fkh7sq$d4u$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1198269414 18025 172.30.248.37 (21 Dec 2007 20:36:54 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 21 Dec 2007 20:36:54 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1215962
Xref: news.mathworks.com comp.soft-sys.matlab:443340



"Ian Clarkson" <ian.clarkson@gesturetek.com> wrote in 
message <fkh7sq$d4u$1@fred.mathworks.com>...
> I'm trying to access all matrix elements NOT having a 
given 
> list of indices.
> 
> For instance,
> 
> abc=[5.8 3.8 2.2 5.8 0.2];
> abc([1 3])
> ans =
>     5.8000    2.2000
> 
> That's a neat way to index the matrix. But I want 
something 
> akin to this:
> 
> abc(![1 3])
> ans =
>     3.8000    5.8000 0.200
> 
> i.e. it gave me all elements not equal to 1 or 3. There 
> must be an elegant way to do this that I'm slightly too 
> dumb to figure out.
> 

Never mind! I figured it out just after submitting it. My 
solution:

unwantedIndices = [1 3];
wantedIndices = 1:length(abc);
wantedIndices(unwantedIndices) = [];

wantedValues = abc(wantedIndices);

This gives the correct answer. Thanks!