Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Preallocation in MATLAB R2009a
Date: Wed, 5 Aug 2009 13:36:42 -0400
Organization: The MathWorks, Inc.
Lines: 35
Message-ID: <h5cfv8$hl$1@fred.mathworks.com>
References: <h5c475$639$1@fred.mathworks.com> <h5cap2$6e9$1@fred.mathworks.com> <h5cekt$3nt$1@fred.mathworks.com> <h5cfn2$dh7$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1249493800 565 172.31.44.65 (5 Aug 2009 17:36:40 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 5 Aug 2009 17:36:40 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: news.mathworks.com comp.soft-sys.matlab:561074



"Oleg Komarov" <oleg.komarov@hotmail.it> wrote in message 
news:h5cfn2$dh7$1@fred.mathworks.com...

*snip*

> a = ones(2,2)
> b(2,2) = 1
> a =
>     1     1
>     1     1
> b =
>     0     0
>     0     1
>
> Lets say now it makes sense. has Yair Altman ever mentioned this?

Why would he?  If you assign a value to an element beyond the bounds of the 
matrix, the elements that need to be created to perform that assignment 
while keeping the matrix rectangular are filled in with 0's.  Note the 
difference between:

a = ones(2, 2)
b1(2, 2) = 1

and:

a = ones(2, 2)
b2(1:2, 1:2) = 1

-- 
Steve Lord
slord@mathworks.com