Path: news.mathworks.com!not-for-mail
From: "Steven_Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Indexing a range of array values using a matrix?
Date: Mon, 12 Mar 2012 10:14:44 -0400
Organization: MathWorks
Lines: 52
Message-ID: <jjl0ck$8m7$1@newscl01ah.mathworks.com>
References: <jjgb6e$qfh$1@newscl01ah.mathworks.com> <jjgkjn$ngt$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: ah-slord.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain;
	format=flowed;
	charset="UTF-8";
	reply-type=response
Content-Transfer-Encoding: 7bit
X-Trace: newscl01ah.mathworks.com 1331561684 8903 172.31.44.77 (12 Mar 2012 14:14:44 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 12 Mar 2012 14:14:44 +0000 (UTC)
In-Reply-To: <jjgkjn$ngt$1@newscl01ah.mathworks.com>
X-Priority: 3
X-MSMail-Priority: Normal
Importance: Normal
X-Newsreader: Microsoft Windows Live Mail 14.0.8089.726
X-MimeOLE: Produced By Microsoft MimeOLE V14.0.8089.726
Xref: news.mathworks.com comp.soft-sys.matlab:760679



"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message 
news:jjgkjn$ngt$1@newscl01ah.mathworks.com...
> "Evan Ruzanski" wrote in message 
> <jjgb6e$qfh$1@newscl01ah.mathworks.com>...
>> Hello,
>>
>> I'm looking to create the following output without using loops. Let's say 
>> I have some array of data:
>>
>> >> arr = [1 7 3 2 1 5 6 7 8 4]'
>>
>> and a matrix that defines a range of indices related to the array:
>>
>> >> arrLocs = [2 4;6 9]
>>
>> whose first column represents the start values and second column 
>> represents the end values of the range to extract from the data array. So 
>> using this example I would like to see the following output:
>>
>> >> out = [0 0;1 0;1 0;1 0;0 0;0 1;0 1;0 1;0 1;0 0]
> ================
>
> I could be missing something obvious, but this makes little sense to me. 
> Your out variable contains lots of zeros even though your input data arr 
> contain none.

The first row of out represents the logical indices that would extract the 
elements between element arrLocs(1, 1) and arrLocs(1, 2) and similarly for 
the second row. The OP's looking to go from indices to a mask. They haven't 
used it to try to index into arr yet.

>> Again, I can do this with loops no problem but I'm trying to avoid loops.
> ===============
>
> Elaborate on why you're trying to avoid loops. It seems like the logical 
> thing to use.

Particularly if that FOR loop will be from 1 to 2, as it will in this case 
since size(arrLocs, 1) is 2.


A slightly stronger way to say what you did, Matt: FOR is not a four-letter 
(key)word in MATLAB anymore.

-- 
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on 
http://www.mathworks.com