vector of strings to cell array

2 次查看(过去 30 天)
I have a list of numbers as strings that I want to assign to a cellarray. I currently just do a for loop to make the assignment but want to know if there is a vectorized way to do it.
A = [1 2 3 4 5 6]';
strA = num2str(A);
B = cell(6,1);
for i=1:length(A)
B{i} = strA(i);
end

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2013-3-7
B=arrayfun(@num2str,A,'un',0)
  2 个评论
John Petersen
John Petersen 2013-3-7
The first answer works. Second one puts all of A in a single cell. Thanks!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by