How to find where certain groups of zeros are located in a cell
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!