Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe11.iad.POSTED!7564ea0f!not-for-mail
From: Walter Roberson <roberson@hushmail.com>
User-Agent: Thunderbird 2.0.0.24 (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$1@fred.mathworks.com> <hrukjn$dda$1@fred.mathworks.com> <hruo0e$5f8$1@fred.mathworks.com> <hruq21$nef$1@fred.mathworks.com> <hrv34k$sic$1@fred.mathworks.com> <hrv49e$fd7$1@fred.mathworks.com> <hrv5v5$742$1@fred.mathworks.com>
In-Reply-To: <hrv5v5$742$1@fred.mathworks.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 28
Message-ID: <_xFEn.4$wV.0@newsfe11.iad>
NNTP-Posting-Host: 24.79.143.47
X-Complaints-To: internet.abuse@sjrb.ca
X-Trace: newsfe11.iad 1273177338 24.79.143.47 (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: news.mathworks.com 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.