How to find the adjecent values of zeros blocks inside a matrix

조회 수: 2 (최근 30일)
CSCh
CSCh 2025년 4월 19일
댓글: Walter Roberson 2025년 4월 22일
Hi lets assume i have a matrix like in the example. I would like to have 2 vectors containing the left and the right of adjecent values of zero blocks of a size 5x3. In the example, would give me Vectorleft1 with five 0.92 values, Vectorright1 with five 0.441 values, Vectorleft2 with five 0.7542 and vectorright2 with five 0.528. The vectors could be inside a cell or something.
  댓글 수: 1
Walter Roberson
Walter Roberson 2025년 4월 19일
The third line of 0.9200 has a 1 x 5 array of zeros. It is not clear from your descriptions that that block should not be located. It is not clear from your description that the zeros being looked for always start in column 2 or column 5.

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

답변 (1개)

Walter Roberson
Walter Roberson 2025년 4월 19일
%guess: a block of 6 zeros should be treated as the first case ?
mask2 = all(Data(:,2:4) == 0,2);
mask5 = all(Data(:,5:7) == 0,2) & ~mask2;
Vectorleft1 = Data(mask2, 1);
Vectorright1 = Data(mask5, 4);
  댓글 수: 2
CSCh
CSCh 2025년 4월 22일
Many Thanks Walter, mayby I try to be more precise, my goal is to find the adjecent column vectors of zero blocks (with a fixed size of 5x3) in matrices (above is just one example, so the blocks can appear everywhere in the matrix) where these have left and right adjecent values along the columns. These column vectors must contain values (no zeros!).
Walter Roberson
Walter Roberson 2025년 4월 22일
[row,col] = find(Data(:,1:end-4) ~= 0 & Data(:,2:end-3) == 0 & Data(:,3:end-2) == 0 & Data(:,4:end-1) == 0 & Data(:,5:end) ~= 0);

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

카테고리

Help CenterFile Exchange에서 Create Block Masks에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by