Combining to two Cells
Mostrar comentarios más antiguos
I 've scouring the web to find a solution but not much success
p = [{2323}]; k = {'hello'};
where I want pk = {'2323hello'}
Pretty much what the concatenate function in excel would do.
Thanks, Stephan
Respuesta aceptada
Más respuestas (2)
Star Strider
el 13 de En. de 2016
Using sprintf is one option:
p = {2323}; k = {'hello'};
pk = {sprintf('%d%s', p{:}, char(k))}
pk =
'2323hello'
2 comentarios
Stephan Richtering
el 13 de En. de 2016
Star Strider
el 13 de En. de 2016
My pleasure.
Vaibhav Awale
el 13 de En. de 2016
1 voto
Hi,
This can be done using the following command:
>> pk = {[num2str(p{:}), k{:}]}
Refer to following documentation for more information about how cell array indexing works:
Hope this helps.
Regards,
Vaibhav
2 comentarios
Stephan Richtering
el 13 de En. de 2016
Vaibhav Awale
el 13 de En. de 2016
Hi Stephan,
Interestingly "num2str" function returns the string if you give string as an input. So, this approach would work even when "p" is a string!
Regards,
Vaibhav
Categorías
Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!