They are not with , (commas separated) they are separated with ; so they are one under the other. but i want one string at the end
concatenate cell
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alexandros
el 20 de Dic. de 2011
Respondida: Eric Tao
el 3 de Feb. de 2018
i have a cell (symbol {} on the variable list) with a=('kkk', 'lll', 'xxx', 'jjj.xls')
and i want to concatenate a so that i can have
b = ('kkk_lll_xxx_jjj.xls')
thank you
2 comentarios
Respuesta aceptada
Andrei Bobrov
el 20 de Dic. de 2011
a={'kkk', 'lll', 'xxx', 'jjj.xls'}';
out = [a(:)';repmat({'_'},1,numel(a))];
out = [out{:}];
out = out(1:end-1);
variant 2
out = cell(1,2*numel(a)-1);
out(1:2:end) = a;
out(2:2:end) = {'_'};
out = [out{:}];
Más respuestas (4)
Jan
el 20 de Dic. de 2011
a = {'kkk'; 'lll'; 'xxx'; 'jjj.xls'}
out = sprintf('%s_', a{:});
out(end) = [];
or:
out = [sprintf('%s_', a{1:end-1}), a{end}];
or:
out = sprintf([repmat('%s_', 1, numel(a)-1), '%s'], a{:});
For very large cell strings, this becomes slow because Matlab forgets to pre-allocate the output properly. Therefore I've written the C-mex function CStr2String:
out = CStr2String(a, '_', 'noTrial')
Eric Tao
el 3 de Feb. de 2018
just type:
b = {strjoin(a,'_')};
Then your b will be a cell as
{'kkk_lll_xxx_jjj.xls'}
0 comentarios
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!