2
votes

I need some help with union two cell arrays.

I have:

data{1} =   'alon'    'shmiel'
values{2} =   'Image'    'Area'

I want to merge them into a union, so that data{1} first and values{2} second:

'alon'   'shmiel'   'Image'    'Area'

I tried:

  1. values{2} = {data{1}(1:2),'Image', 'Area'};
    but I got: {1x2 cell} 'Image' 'Area'

  2. union(data{1},values{2})
    but I got: 'Area' 'Image' 'alon' 'shmiel'

  3. union(data{1},values{2},'stable')
    but I got an error: Warning: Third argument is ignored for cell arrays.

Thank you guys!

1

1 Answers

1
votes

Do you really want a union (i.e. only unique values)? Or do you just want to concatenate the arrays, as suggested by your first attempt?

If you just want to concatenate, try

horzcat(data{1},values{2})