Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: concatenate cell array
Date: Wed, 1 Jul 2009 18:30:17 +0000 (UTC)
Organization: Universit&#228;tsSpital Z&#252;rich
Lines: 28
Message-ID: <h2g9vp$7rm$1@fred.mathworks.com>
References: <h2g8m1$e5k$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1246473017 8054 172.30.248.38 (1 Jul 2009 18:30:17 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 1 Jul 2009 18:30:17 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 11
Xref: news.mathworks.com comp.soft-sys.matlab:552118


"Diego Lass" <dlISCool@gmail.com> wrote in message <h2g8m1$e5k$1@fred.mathworks.com>...
> Hi 
> I would like to concatenate cell array in a loop
> 
> A = {}
> for ...
>      if ...
>          concatenate A
>       end
> end
> 
> What is the most efficient way to do this?
> 
> p.s. I tried A = { A, {new cell array}  }, it did not work. 
> 
> Thanks
> Diego

one of the solutions
- iff you know the loop's max...

     n=5;
     c=cell(n,1);     % <- preallocation
for  i=1:n
     c{i}=rand(1,i);     % <- index into preallocated CELL
end

us