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

3 ビュー (過去 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 Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by