How to identify specific ranges of regions in an array which add up to a number?
2 views (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
Image Analyst
on 30 Jul 2014
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.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!