Ben Barrowes
Ben Barrowes

Reputation: 103

How to concatenate strings in a cell array in matlab

I am trying to concatenate strings in a cell array using repmat in matlab.

What I want to do is something like:

aa={'xx','yy',repmat({'zz'},1,3)}

with the result equivalent to:

aa={'xx','yy','zz','zz','zz'}

but instead the result is:

{'xx','yy', {1x3 cell array} }

I realize that if I had a variable such as C=repmat('zz',1,3) then I could do

aa{'xx','yy',C{:}}

but the problem is I don't want to define any other variables like C. I want to do this in line if possible. Any ideas?

Upvotes: 0

Views: 241

Answers (1)

user2999345
user2999345

Reputation: 4195

use vector concatenation:

aa=[{'xx','yy'},repmat({'zz'},1,3)]

aa = 
    1×5 cell array

     'xx'    'yy'    'zz'    'zz'    'zz' 

Upvotes: 2

Related Questions