필터 지우기
필터 지우기

How do i count the no of ones of 3D matrix?

조회 수: 3 (최근 30일)
ting
ting 2013년 11월 22일
댓글: ting 2013년 11월 23일
  1. 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?
  2. 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
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()?
ting
ting 2013년 11월 22일
i want to perform 3d dct so, i need to build a block of size 8*8*8. Do we need to assign an index so that i can reconstruct them ?

댓글을 달려면 로그인하십시오.

채택된 답변

Azzi Abdelmalek
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);
  댓글 수: 1
ting
ting 2013년 11월 23일
Thank you. Before i cut the big matrix, all value in this matrix is either 1 or 0; say 3XXXX ones in that matrix. After cutting them into 8*8*8 I still have a problem, the out is 34*34*34 blocks, each block is 8*8*8, how can i count the number of 1?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by