How to create a cell of strings from a vector?
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Oleg Komarov
2012-9-10
编辑:Oleg Komarov
2012-9-10
Encapsulate sprintf() into arrayfun():
arrayfun(@(in) sprintf('%.0f', in), x,'un',0)
4 个评论
Tom
2012-9-10
If you add left justify to the format it removes the leading spaces:
cellstr(num2str(x','%-0.0f'))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Large Files and Big Data 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!