Path: news.mathworks.com!not-for-mail
From: Loren Shure <loren@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Get the first element out of each cell of a cell array
Date: Thu, 13 Mar 2008 08:41:58 -0400
Organization: The MathWorks
Lines: 34
Message-ID: <MPG.2242eb224cf0bf8c989824@news.mathworks.com>
References: <fr6rl1$ifj$1@fred.mathworks.com> <fr7q09$1vn$1@fred.mathworks.com>
NNTP-Posting-Host: shurel.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-15"
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1205412118 7748 172.31.57.117 (13 Mar 2008 12:41:58 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 13 Mar 2008 12:41:58 +0000 (UTC)
User-Agent: MicroPlanet-Gravity/2.70.2067
Xref: news.mathworks.com comp.soft-sys.matlab:457007



In article <fr7q09$1vn$1@fred.mathworks.com>, us@neurol.unizh.ch says...
> "David Doria":
> <SNIP first in line only...
> 
> > I have a cell 4x20 cell array called L
> > each element of L is a 1x20 vector
> > How do I make a vector of all the first elements of L
> (1,:)?
> > I tried L(1,:)(1) to no avail...
> 
> one of the many solutions
> 
> % the data
>      c=cell(2,3); % <- your 4x20 cell array
>      [c{:}]=deal(1:3); % <- each element being a vec
> % the engine
>      ca=cat(1,c{:});
>      r=ca(:,1);
> % the result (as expected)
>      disp(c);
>      disp(r.');
> % 1 1 1 1 1 1
> 
> us
>      
> 
caveat that all cells need to have same number of elements for this 
solution, I think.

the cellfun solution listed earlier works even if that's not the case.

-- 
Loren
http://blogs.mathworks.com/loren/