How to identify specific ranges of regions in an array which add up to a number?

2 次查看(过去 30 天)
I have created a binary matrix (1xlength). I need MATLAB to go through the matrix and spit out the regions (region lengths can vary between 40 and 60 spaces) that add up to a given number, lets say 50.
I have no clue how to approach this. Any help is appreciated. Thanks!

回答(1 个)

Image Analyst
Image Analyst 2014-7-30
Pretty trivial if you have the Image Processing Toolbox. Do you? Type ver to find out.
labeledMatrix = binaryMatrix;
measurements = regionprops(labeledMatrix, 'Area');
allAreas = [measurements.Area]; % Extract from structure array to numerical array.
area50RegionIndexes = find(allAreas == 50); % Indexes of regions whose area = 50.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by