How to convert convert a cell{x,y,...}(V,W) into an array(x,y,...,V,W) with an "automatic process" ?
이전 댓글 표시
Dear all,
My problem is the following. I have 1 cell array "cell{x,y,...}(V,W)" with one numeric array (V,W) in each cell {x,y,...} (all of these numeric arrays have the same size and the same dimensions). I need to convert this cell array into a numeric array which have the following "topology": array(x,y,...,V,W). The difficulty is that the conversion "has to be automatic" for any size of the cell array (in other word, it has to work for any number of dimensions x, y, ... and for any number of different values that these dimensions can take). I thought about a lot of ways to code that (with "for" loops and function "eval" or with "cell2mat" function or ...) but it doesn't work. Do you have any idea ?
Thank you in advance,
Quentin
댓글 수: 1
Azzi Abdelmalek
2013년 9월 6일
Can you give an example of cell{x,y,...}(V,W) ?
채택된 답변
추가 답변 (2개)
Azzi Abdelmalek
2013년 9월 7일
v=2;
w=9;
tic
n=[size(a) v w];
out1=zeros(n);
idx1= repmat({':'},1,ndims(a));
for k=1:v
for p=1:w
idx= [idx1 {k} {p}];
out1(idx{:})=cellfun(@(x) x(k,p),a);
end
end
% But the result is different from Andrei's result
Azzi Abdelmalek
2013년 9월 6일
v=2;
w=9;
n=[size(a) v w];
out=zeros(n);
for k=1:v
for p=1:w
out(:,:,:,k,p)=cellfun(@(x) x(k,p),a);
end
end
disp(out)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!