COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Assigning Cell Array to Portion of Another Cell Array

• Email
• 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 (25) 7/31/2012 7:00:42 PM

See related articles to this posting

```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 (7455) 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 (1248) 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 (7455) 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 (25) 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 (7455) 8/2/2012 11:39:10 AM

5 Replies
37 Views

Similar Articles

12/9/2013 4:02:01 PM
page loaded in 39653 ms. (0)