From: Walter Roberson <>
User-Agent: Thunderbird (Macintosh/20100228)
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: Re: What a hell is wrong with logical indexing??? Really???
References: <hrujad$fmn$> <hrukjn$dda$> <hruo0e$5f8$> <hruq21$nef$> <hrv34k$sic$> <hrv49e$fd7$> <hrv5v5$742$>
In-Reply-To: <hrv5v5$742$>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 28
Message-ID: <_xFEn.4$wV.0@newsfe11.iad>
X-Trace: newsfe11.iad 1273177338 (Thu, 06 May 2010 20:22:18 UTC)
NNTP-Posting-Date: Thu, 06 May 2010 20:22:18 UTC
Date: Thu, 06 May 2010 15:22:17 -0500
Xref: comp.soft-sys.matlab:633295

Sergei Koulayev wrote:
>  As a user, I don't mind bumping up from logical
> to double, or from int8 to double, if that's necessary to give me a 
> result I want. Just imagine that I create a variable X somewhere on the 
> line #12 and it just happened to be stored at Integer. Or Logical. Then 
> later at the line #133 I try to write X(3)=pi. I really want this "pi" 
> to be there! Instead of doing just what I told him to do - just put the 
> number in there - Matlab is *invisibly* correcting my operation, giving 
> me a wrong answer that I didn't expect. Who would be happy about that? I 
> want "what you see is what you get" as a consistent behavior.

I know some languages that can do that with respect to some indexable 
objects (e.g., Maple lists), but I cannot think of _any_ language that 
will do that for objects that have been formally declared as arrays. I 
dunno... LISP might if anything does.

What I would suggest to you, Sergei, is to use cell arrays for all of 
your work instead of numeric arrays.

X{3} = pi;

*will* change the datatype of X{3} to double.

You will largely lose the ability to vectorize numeric computations, but 
if you want WYSIWYG storage then you are going to lose efficiency anyhow.