How do you transform a vector of numbers into a cell of strings?
1 次查看(过去 30 天)
显示 更早的评论
I have a vector of numbers:
A = [1 2 3 4 5]';
I want to change it to a cell of strings, such as the one I've declared here:
B = cell(5,1); B{1} = '1'; B{2} = '2'; B{3} = '3'; B{4} = '4'; B{5} = '5';
How can I change A into B without using a for loop?
0 个评论
采纳的回答
更多回答(1 个)
Titus Edelhofer
2014-6-27
Hi,
one possibility:
Acell = num2cell(A);
B = cellfun(@(x) sprintf('%g', x), Acell, 'UniformOutput', false);
Titus
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!