Path: news.mathworks.com!not-for-mail
From: "Branko " <bogunovic@mbss.org>
Newsgroups: comp.soft-sys.matlab
Subject: Re: cell array
Date: Fri, 23 Oct 2009 09:16:03 +0000 (UTC)
Organization: National Institute of Biology
Lines: 36
Message-ID: <hbrs8j$6h3$1@fred.mathworks.com>
References: <hbrp39$me3$1@fred.mathworks.com> <hbrr50$gfq$1@fred.mathworks.com>
Reply-To: "Branko " <bogunovic@mbss.org>
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 1256289363 6691 172.30.248.38 (23 Oct 2009 09:16:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 23 Oct 2009 09:16:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 237386
Xref: news.mathworks.com comp.soft-sys.matlab:579526


"Vinayagam " <bkvinay2001@yahoo.com> wrote in message <hbrr50$gfq$1@fred.mathworks.com>...
> Try this one,
> 
> [Z{:,1}]'-[Z{:,2}]'.
> 
> --
> Vinayagam.
> 
> "sujata " <sujatagp@gmail.com> wrote in message <hbrp39$me3$1@fred.mathworks.com>...
> > I have a 5 by 2 cell array that is only filled with numbers. Something like this:
> > Z = 
> >    [ 1.6168]    [ 0.8652]
> >     [ 0.5724]    [ 0.2323]
> >     [ 2.5916]    [ 2.6805]
> >     [-5.1700]    [      0]
> >     [ 1.4836]    [ 0.4542]
> >     [-0.1367]    [      0]
> >     [ 2.5100]    [ 2.9110]
> >            []           []
> >     [ 1.7531]    [ 1.7531]
> >     [-0.6462]    [-0.6462]
> > 
> > but i want to take the difference between these two columns. Since it is an cell array this is not possible to simply do Z(:,1)-Z(:,2).
> > 
> > I could use a for loop but i want to avoid using that. I also looked in the documentation for cell conversions but so far no luck. 
> > 
> > Does anyone know (if) there is an alternative way to do this?
> > 

Why do you need cell array? If you have mix type of data (string,numeric) or different size of arrays is good otherwise as, Arun mentioned transform to matrix and do your operation. 

Moreover, be careful about empty cells - replace them with NaN and NOT 0 since this represents number!

Very useful function to look is bsxfun.

Branko