0

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?

1 Answer 1

2

use vector concatenation:

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

aa = 
    1×5 cell array

     'xx'    'yy'    'zz'    'zz'    'zz' 
Sign up to request clarification or add additional context in comments.

4 Comments

Good. This works, but is there no way to do this with a function on repmat? What I was hoping for is a function that takes a cell array and converts it into a comma separated list, i.e. that reproduces the C{:} behavior. For example: colonoperator(repmat({'zz'},1,3)) that outputs a comma separated list.
@BenBarrowes You honestly can't. Why are you opposed to temporary variables?
does reshape([{'xx','yy'},repmat({'zz'},1,3)],[],1) work for you?
I tried using subsref to get a comma separated list from a cell array, but that does not seem to work for cells though it does for numerical arrays:groups.google.com/forum/#!topic/comp.soft-sys.matlab/… user2999345 your suggestion also works, but I was hoping for a function that operates on a cell array to produce a comma separated list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.