Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Preallocation in MATLAB R2009a
Date: Wed, 5 Aug 2009 18:22:20 +0000 (UTC)
Organization: Universit&#228;tsSpital Z&#252;rich
Lines: 33
Message-ID: <h5cikr$jh$1@fred.mathworks.com>
References: <h5c475$639$1@fred.mathworks.com> <h5c9nq$fsm$1@fred.mathworks.com> <h5cgs2$52$1@fred.mathworks.com> <h5chq4$3nt$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1249496540 625 172.30.248.35 (5 Aug 2009 18:22:20 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 5 Aug 2009 18:22:20 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 11
Xref: news.mathworks.com comp.soft-sys.matlab:561090


"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <h5chq4$3nt$1@fred.mathworks.com>...
> 
> > 
> > Thank U very much&#65281;
> > Maybe I didn't make it clear, my puzzle is what result in the  huge speed difference between "a = zeros(m,n)" and "a(m,n)= 0",since zeros is a built-in function and has good efficience.
> > I'm guessing "a(m,n) = 0" just do a few things like labeling the beginning and end of the variable in memory, since free memory space are all 0s.
> 
> No, I don't believe. My theory is simply poor programming of ZEROS function. Oh well. Good to know though.
> 
> Bruno

nah... just call it ...correctly...

%    clear all;     % <- use this for proper testing...
     clear r;     % <- save old stuff!
     n=5000;
tic;
     r(ones(n))=0;
toc
    clear r;
tic;
     r=zeros(n);
toc
     clear r;
tic
     r=zeros(n,'double');
toc
% results on a wintel sys: ic2/2*2.6gzh/2gb/winxp32.sp3/r2009a
% Elapsed time is 0.646796 seconds.     ONES
% Elapsed time is 0.163560 seconds.     ZEROS
% Elapsed time is 0.001191 seconds.     ZEROS(...,'double')

us