How to create a cell of strings from a vector?
Show older comments
I have the vector
x = [ 10.027 20.35 50.1 100.002 ]
which I would like to convert to the cell
x = { '10', '20', '50', '100' }.
How can I do this? I know I can use sprintf('%.0f\n', x) to get the formatting I want, but not how to turn the outputs into a cell of strings.
Accepted Answer
More Answers (2)
Perhaps this is faster:
Str = sprintf('%.0f*', x);
C = regexp(Str, '*', 'split');
1 Comment
Oleg Komarov
on 10 Sep 2012
Nifty!
Tom
on 10 Sep 2012
Based on Sean De Wolski's answer:
cellstr(num2str(x','%-0.0f'))
Categories
Find more on Characters and Strings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!