vector of strings to cell array

3 ビュー (過去 30 日間)
John Petersen
John Petersen 2013 年 3 月 7 日
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 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 7 日
編集済み: Azzi Abdelmalek 2013 年 3 月 7 日
or
B=cellstr(num2str(A))
John Petersen
John Petersen 2013 年 3 月 7 日
The first answer works. Second one puts all of A in a single cell. Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by