sum different cell arrays based on index
이전 댓글 표시
Hello, i have
A = { [0,1,0; 0,0,0; 0,0,0],...
[1,0,0; 0,0,0; 0,1,1],...
[0,0,0; 0,1,0; 0,0,0],...
[0,0,0; 0,1,0; 0,0,0],...
[0,0,1; 0,0,0; 1,0,0],...
[1,1,0; 0,0,0; 0,0,0],...
[0,0,0; 0,0,1; 0,0,0]} ;
and i = { [1,2,3], [4,5,6,7] }
i need to sum A based on index groups resulting B={ [1,1,0; 0,1,0; 0,1,1], [1,1,1; 0,1,1; 1,0,0] }, how can i do this?
댓글 수: 1
F = @(x)sum(cat(3,A{x}),3);
B = cellfun(F,id,'uni',0);
celldisp(B)
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!