user3527150
user3527150

Reputation: 926

Concatenate two string with comma

I am newer in MATLAB. I have a code like this

results=a(1,1)+','+a(1,2);

a is an array of words. I just want to concatenate the first two words in my array.

After running I get this error:

Undefined function or method 'plus' for input arguments of type 'cell'

Upvotes: 0

Views: 554

Answers (2)

chappjc
chappjc

Reputation: 30579

How about strjoin:

strjoin(a(1,1:2).')

Generally, it takes a row cell array. If you have a column, the transpose is necessary. A basic example,

>> c = {'banana';'orange'}
>> strjoin(c(:)',',')
ans =    

banana,orange

Upvotes: 1

buzjwa
buzjwa

Reputation: 2652

Your error suggests that a is a cell array, which means you use curly brackets ({}) to access the data inside it. You can concatenate like this:

results = [a{1,1} a{1,2}];

Upvotes: 1

Related Questions