create a cell array of numbers
7 次查看(过去 30 天)
显示 更早的评论
hi
i need to create a cell array with numbers from 0000-1000
notice that numbers must be in a 4-digit format
how can i do this?
thanks
3 个评论
Walter Roberson
2019-4-25
linspace(1,100,1000) would contain non-integer values, which cell would not be able to use a dimension sizes to construct a 1000-dimensional cell array.
采纳的回答
更多回答(1 个)
Walter Roberson
2013-6-16
No. In MATLAB, numbers automatically drop leading 0's when displayed.
What is possible is to create a cell array of strings from '0000' to '1000'.
cellstr(num2str(0:1000).', '%04d')
Note: the .' is required there; without it the strings would come out wrong.
5 个评论
Walter Roberson
2020-5-28
There is also the undocumented
sprintfc('%04d', 0:1000)
Also since R2016b, there has also been
compose('%04d', 0:1000)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!