How to convert the contents of a cell array into an array?
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi, I have a cell array that looks a bit like this:
N='AA' 'AA_BB' 'AA_BB_CC' 'AA_BB_DD' 'AA_BB_EE'
it is easy enough to convert a specific entry of my cell into an array:
a=cell2mat(N(2)) a=AA_BB
Now I want to use the cellfun code in order to generate an array for all the entries in my cell. The end result I am envisioning looks a bit like:
a=AA AA_BB AA_BB_CC AA_BB_DD AA_BB_EE
I am trying the following code:
a=cellfun(cell2mat,N)
but I am getting an error message. Where am I going wrong? Thanks
댓글 수: 2
답변 (1개)
Jan
2013년 9월 10일
편집: Jan
2013년 9월 10일
This is not a job for cellfun. And if it is one, a function handle would be required: cellfun(@cell2mat, ...) .
N = {'AA', 'AA_BB', 'AA_BB_CC', 'AA_BB_DD', 'AA_BB_EE'};
a = sprintf('%s ', N{:}); % Has a trailing space
% Or:
b = cat(2, N{:}); % No intermediate spaces
% Or:
c = CStr2String(N, ' ', 0);
댓글 수: 5
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!