How do i count the no of ones of 3D matrix?
3 次查看(过去 30 天)
显示 更早的评论
- I have a big 3-D matrix, say 272*272*272, but contains either 0 or 1; how do i count the number of ones?
- In my project, i need to form a 8*8*8 cube (that why i choose the matrix is 272*272*272). How can i cut this big matrix into 8*8*8 and assign a index for every cube(8*8*8)?
2 个评论
Image Analyst
2013-11-22
Why do you need an index? What's wrong with the x,y,z value of the center? What are you going to do? Would you like to use blockproc()?
采纳的回答
Azzi Abdelmalek
2013-11-22
编辑:Azzi Abdelmalek
2013-11-22
If A is your array
no1=sum(A(:))
For second question
A=rand(272,272,272);
idx2=8:8:272;
idx1=[1 idx2(1:end-1)+1];
n=numel(idx1);
[ii,jj,hh]=ndgrid(1:n,1:n,1:n);
out=arrayfun(@(x,y,z) A(idx1(x):idx2(x),idx1(y):idx2(y),idx1(z):idx2(z)),ii,jj,hh,'un',0);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!