0
votes

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.

1
Do you want numbers or numstrings, i.e. 35 or '35'? - Oleg

1 Answers

1
votes

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'