Thread Subject: cell array

Subject: cell array

From: sujata

Date: 23 Oct, 2009 08:22:01

Message: 1 of 6

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?

Thanks

Subject: cell array

From: arun

Date: 23 Oct, 2009 08:51:34

Message: 2 of 6

On Oct 23, 10:22 am, "sujata " <sujat...@gmail.com> wrote:
> 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?
>
> Thanks

help cell2mat

but the problem is that if your cell has [] in both the columns, the
entry will be eliminated. I suggest you just replace the empty values
with 0's and then convert using cell2mat and perform the operations
and then convert back to cell if necessary...

but, if all your values are cell, then why go for cell? it just takes
up more space..

best, arun.

Subject: cell array

From: Vinayagam

Date: 23 Oct, 2009 08:57:04

Message: 3 of 6

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?
>
> Thanks

Subject: cell array

From: Branko

Date: 23 Oct, 2009 09:16:03

Message: 4 of 6

"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

Subject: cell array

From: sujata

Date: 23 Oct, 2009 09:34:20

Message: 5 of 6

The reason that the cell is used is because I draw the data from a database and it puts it automatically into an cell array since it consists of numeric and strings.
But then i select only the columns which I need and incidentally this is the data.

That's why i am trying to filter out the cell.

Thanks for the ideas

"Branko " <bogunovic@mbss.org> wrote in message <hbrs8j$6h3$1@fred.mathworks.com>...
> "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

Subject: cell array

From: rajagiri

Date: 23 Oct, 2009 09:37:21

Message: 6 of 6

better you can use basic array format.

[url=http://www.repairsharks.com]ipod repair solutions[/url]

[url=http://www.repairsharks.com/apple-ipod-repair]cheap apple-ipod service[/url]

[url=http://www.repairsharks.com/about.php]xbox 360 repair[/url]

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
bsxfun Branko 23 Oct, 2009 05:19:10
cell array sujata 23 Oct, 2009 04:24:09
rssFeed for this Thread

Contact us at files@mathworks.com