Combining to two Cells
Show older comments
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
Accepted Answer
More Answers (2)
Star Strider
on 13 Jan 2016
Using sprintf is one option:
p = {2323}; k = {'hello'};
pk = {sprintf('%d%s', p{:}, char(k))}
pk =
'2323hello'
Vaibhav Awale
on 13 Jan 2016
1 vote
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 Comments
Stephan Richtering
on 13 Jan 2016
Vaibhav Awale
on 13 Jan 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
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!