필터 지우기
필터 지우기

Is there a way to find number of blocks in a matrix?

조회 수: 5 (최근 30일)
Omar B.
Omar B. 2021년 6월 15일
댓글: Omar B. 2021년 6월 15일
I have a matrix that has 5 blocks along the diagonal and two consecutive blocks overlap in one diagonal element.
How can I compute the number of blocks in MATLAB?
  댓글 수: 3
Omar B.
Omar B. 2021년 6월 15일
As an example:
A=[1 2 0 0 0 0 0 0 0;3 4 5 6 0 0 0 0 0; 0 7 8 9 0 0 0 0 0; 0 1 2 3 4 5 0 0 0;0 0 0 1 2 3 0 0 0;0 0 0 1 2 3 4 5 0;0 0 0 0 0 1 2 3 0;0 0 0 0 0 1 2 3 4; 0 0 0 0 0 0 0 1 2]
How can I compute the number of blocks in MATLAB?
Joseph Cheng
Joseph Cheng 2021년 6월 15일
can you explain what you mean by a block?

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

채택된 답변

Stephen23
Stephen23 2021년 6월 15일
편집: Stephen23 2021년 6월 15일
Assuming that the blocks do not contain zeros:
A = [1,2,0,0,0,0,0,0,0;3,4,5,6,0,0,0,0,0;0,7,8,9,0,0,0,0,0;0,1,2,3,4,5,0,0,0;0,0,0,1,2,3,0,0,0;0,0,0,1,2,3,4,5,0;0,0,0,0,0,1,2,3,0;0,0,0,0,0,1,2,3,4;0,0,0,0,0,0,0,1,2]
A = 9×9
1 2 0 0 0 0 0 0 0 3 4 5 6 0 0 0 0 0 0 7 8 9 0 0 0 0 0 0 1 2 3 4 5 0 0 0 0 0 0 1 2 3 0 0 0 0 0 0 1 2 3 4 5 0 0 0 0 0 0 1 2 3 0 0 0 0 0 0 1 2 3 4 0 0 0 0 0 0 0 1 2
[R,~] = find(diff(~A,1,1)>0);
N = 1+numel(unique(R))
N = 5
If the blocks can contain zeros, then you will probably need to use some pattern matching.

추가 답변 (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