sum different cell arrays based on index
Show older comments
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 Comment
F = @(x)sum(cat(3,A{x}),3);
B = cellfun(F,id,'uni',0);
celldisp(B)
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!