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일

0 개 추천

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개)

카테고리

도움말 센터 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by