필터 지우기
필터 지우기

How to find where certain groups of zeros are located in a cell

조회 수: 2 (최근 30일)
Benjamin Azrieli
Benjamin Azrieli 2020년 11월 25일
답변: Amrtanshu Raj 2020년 12월 1일
As a follow up question to this answer provided by Image Analyst - Lets say I wanted to locate the group of 4 zeros in the array, how would I go about that?
An example of my desired output is this:
I just recently used this code on a cell array of strings, x, to provide the locations of cells containing the string 'Cut A'.
x = table2cell(RS422_table(1,1));
idx = find(strcmp(x{1,1}(1,:), 'Cut A'));
idx =
Columns 1 through 8
3631 3632 3633 3634 3635 3636 3637 3638
Columns 9 through 16
3639 3640 3641 3642 3643 3644 3645 3646
Columns 17 through 24
3647 3648 3649 3650 3651 3652 3653 3654
Columns 25 through 30
3655 3656 3657 3658 3659 3660
where each entry in idx is a position of a string 'Cut A' in a group that was found.
How can I do this with groups of zeros instead?
My MATLAB Release is 2018b

채택된 답변

Amrtanshu Raj
Amrtanshu Raj 2020년 12월 1일
Hi,
Assuming you want to find the first index of all the groups of 4 zeros in a array. Here is the code -
arr = [1 0 1 0 0 1 1 1 1 0 0 0 0 1 1 0 1 0 0 0 0 1 1 1 0 0 0 0 1 1 0 1 0]; %sample Data
[lb,num] = bwlabel(arr==0); %find groups of zeros
k = regionprops(lb,'Area'); %Find number of zeros in each group
for i=1:num
if k(i).Area==4 %check the groups for which number of zeros is 4
find(lb==i,1) %find the start index of those groups
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by