0

I'm trying to concatenate two arrays as follows:

z={ '35' {'test'} ; '45' {'test'}}
z={z{:} ;{'55' {'test'}}}

I would expect the result to be

 {35 {'test'}
 45  {'test'}
 55 {'test'}}

but instead I get:

Error using vertcat

Dimensions of matrices being concatenated are not consistent.

What am I forgetting? Thanks.

Carbon
  • 3,828
  • 3
  • 24
  • 51

1 Answers1

1

The error is caused by z{:} which lists all content of z 'into' a N by 1 vector and when you try to collect all the elements with the outer {} it throws the error due to mismatching dimensions.

You might be using too many { } and you can concatenate cell arrays with [ ]:

z = { '35' 'test'
     '45'  'test'};
z = [z; {'55' 'test'}]

The command window will display:

z = 
    '35'    'test'
    '45'    'test'
    '55'    'test'
Oleg
  • 10,406
  • 3
  • 29
  • 57
  • Sorry, I'd like the second element to be a nested cell array if possible. Is it still possible to cat them? Never mind, figured it out: z={ '35' {'test'} ; '45' {'test'}}; z=[z;{'55' {'derp'}}; Thanks! – Carbon Jun 26 '13 at 21:20