Reputation: 5789
var is 1x6 cell
var =
'a' 'b' 'v' 'g' 'd' 'r'
I would like to convert it to obtain a list with sparated comma 'a','b','v','g','d','r'
any idea ?
Thanks
Upvotes: 1
Views: 4001
Reputation: 686
Much nicer, from Matlab 2013a onwards:
>> c = {'a', 'b', 'v', 'g', 'd', 'r'};
>> strjoin( c, ', ')
ans =
'a, b, v, g, d, r'
Upvotes: 1
Reputation: 112679
Clumsy one-liner:
cell2mat(strcat(var, [mat2cell(repmat(',',1,length(var)-1), 1, ones(1,length(var)-1)),{''}]))
Upvotes: 0
Reputation: 25232
These two lines will do it:
c = {'a', 'b', 'v', 'g', 'd', 'r'};
d = [c',[repmat({','},numel(c)-1,1);{[]}]]';
e = [d{:}]
returns:
e = a,b,v,g,d,r
Upvotes: 1