Path: news.mathworks.com!newsfeed-00.mathworks.com!kanaga.switch.ch!irazu.switch.ch!news-zh.switch.ch!switch.ch!news.belwue.de!news.n-ix.net!news2.arglkargh.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: logical indexing with larger logical array
Date: Fri, 05 Nov 2010 11:06:13 -0500
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <ib1aab$lo9$1@news.eternal-september.org>
References: <ib0jl3$6es$1@fred.mathworks.com> <ib0lbg$p9c$1@fred.mathworks.com> <ib0vne$6lh$1@fred.mathworks.com> <ib11rk$k4p$1@news.eternal-september.org> <ib139n$3bh$1@fred.mathworks.com> <ib14sb$kbp$1@fred.mathworks.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 5 Nov 2010 16:10:52 +0000 (UTC)
Injection-Info: mx02.eternal-september.org; posting-host="t7YQg5oy1WBTQEoqpvq/DA";
	logging-data="22281"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX199hpzd9OVWyrHugqwfRUau"
User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
In-Reply-To: <HIDDEN>
Cancel-Lock: sha1:bsdRR6PpJ6UO0muUzs2V6fB3tyo=
Xref: news.mathworks.com comp.soft-sys.matlab:684192

Bruno Luong wrote:
> To me it looks like the logical indexing engine performs the bound 
> checking with *every* elements that corresponds to TRUE. That's why it 
> issues an error with outside TRUE and not outside FALSE. If the checking 
> is performed once before the scan on the sizes of the array and the 
> logical array, there might be some speed gain.
> 
> I agree that the virtue of being able of passing FALSE beyond the limit 
> is ...none. It likely a bug of the program when such calling occurs, and 
> the programmer should be alerted.
> 
> When the logical array is shorter, Matlab pads the missing tail with 
> FALSE. This behavior is documented and useful.
> 
> In any case, the behavior when invoking with longer logical array must 
> be documented.

The "bad" behavior imo is this (sticking w/ David's example) --

 >> a(l(size(a)))
ans =
      1     3
 >> a(l)
ans =
      3
      4
 >>

The behavior of concatenating 'false' in shorter in vectors is clear; 
what is perverse is the conversion to linear indexing in the 2D (and 
presumably higher altho I didn't check it) that returns a somewhat 
surprising result when the logic array is mapped onto the indexed array.

IMO it's too bad the behavior wasn't codified as in the first of the two 
snippets above but I'd consider not breaking old code probably of higher 
import than fixing the behavior at this point.

--