Assigning Cell Array to Portion of Another Cell Array

  • Follow


I have a bunch of 1D cell arrays that I wish to combine into a 2d cell array matrix.  I am having trouble coming up with a statement that will do this.  My current plan of action is to create my 2D cell array and then assign each 1D array to a particular column of the 2D array.

So I have a 1D cell array:
a = 
    'ay'
    'be'
    'ce'
    'de'

I make a 2D cell array:
c = cell(4,10);

I want to stick the contents of a{1} into c{1,5}.  Then I want to stick the contents of a{2} into c{2,5}.  and so on for all 4 elements of a.  

when I try the statement: 
c{:,5} = a
I get the error: "The right hand side of this assignment has too few values to satisfy
 the left hand side."

Can anyone explain what I have to do to get this to work?  I have experimented with using (a) or a(:) etc to no avail.

Thank you.
0
Reply brspam (22) 7/31/2012 7:00:42 PM

On 7/31/2012 2:00 PM, Ben Ruppel wrote:
> I have a bunch of 1D cell arrays that I wish to combine into a 2d cell
> array matrix. I am having trouble coming up with a statement that will
> do this. My current plan of action is to create my 2D cell array and
> then assign each 1D array to a particular column of the 2D array.
>
> So I have a 1D cell array:
> a = 'ay'
> 'be'
> 'ce'
> 'de'
>
> I make a 2D cell array:
> c = cell(4,10);
>
> I want to stick the contents of a{1} into c{1,5}. Then I want to stick
> the contents of a{2} into c{2,5}. and so on for all 4 elements of a.
> when I try the statement: c{:,5} = a
....

 >> a = {'ay' 'be' 'ce' 'de'}';
 >> c=cell(4,10);
 >> [c{:,5}]=deal(a{:})
c =
     []       []     []     []    'ay'     []     []     []     []     []
     []       []     []     []    'be'     []     []     []     []     []
     []       []     []     []    'ce'     []     []     []     []     []
     []       []     []     []    'de'     []     []     []     []     []
 >>

--
0
Reply none1568 (6639) 7/31/2012 7:23:45 PM


In article <jv9bc1$1ra$1@speranza.aioe.org>, dpb <none@non.net> wrote:

> On 7/31/2012 2:00 PM, Ben Ruppel wrote:
> > I have a bunch of 1D cell arrays that I wish to combine into a 2d cell
> > array matrix. I am having trouble coming up with a statement that will
> > do this. My current plan of action is to create my 2D cell array and
> > then assign each 1D array to a particular column of the 2D array.
> >
> > So I have a 1D cell array:
> > a = 'ay'
> > 'be'
> > 'ce'
> > 'de'
> >
> > I make a 2D cell array:
> > c = cell(4,10);
> >
> > I want to stick the contents of a{1} into c{1,5}. Then I want to stick
> > the contents of a{2} into c{2,5}. and so on for all 4 elements of a.
> > when I try the statement: c{:,5} = a
> ...
> 
>  >> a = {'ay' 'be' 'ce' 'de'}';
>  >> c=cell(4,10);
>  >> [c{:,5}]=deal(a{:})


It's much simpler than that.

  c(:,5) = a;

is all you need.

-- 
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.
0
Reply see9548 (1239) 7/31/2012 9:49:38 PM

On 7/31/2012 4:49 PM, Doug Schwarz wrote:
....

> It's much simpler than that.
>
>    c(:,5) = a;
>
> is all you need.

Yeah, dawned on me later--not sure why I went there but thanks... :)

--



0
Reply none1568 (6639) 7/31/2012 10:15:36 PM

dpb <none@non.net> wrote in message <jv9lec$40l$1@speranza.aioe.org>...
> On 7/31/2012 4:49 PM, Doug Schwarz wrote:
> ...
> 
> > It's much simpler than that.
> >
> >    c(:,5) = a;
> >
> > is all you need.
> 
> Yeah, dawned on me later--not sure why I went there but thanks... :)
> 
> --
> 
> 
Thank you both, that did the trick.  I am pretty clueless about when to use {} vs () but I'm starting to see some patterns.
0
Reply brspam (22) 8/1/2012 10:23:04 PM

On 8/1/2012 5:23 PM, Ben Ruppel wrote:
....

> ... I am pretty clueless about when to
> use {} vs () but I'm starting to see some patterns.

<http://www.mathworks.com/help/techdoc/matlab_prog/br04bw6-117.html>

--
0
Reply none1568 (6639) 8/2/2012 11:39:10 AM

5 Replies
28 Views

(page loaded in 0.073 seconds)


Reply: