How to find the length of segments of a matrix that meet certain condition?

5 次查看(过去 30 天)
Hi guys, I am trying hard to think of an algorithm for this, but no luck.
If I have a matrix a = [77 77 77 79 79 79 77 77 77 77];
And I want to find the length of segments that are equal to 77 (3 and 4).
What is the most efficient way to do this?
thank you very much for your help!

采纳的回答

Image Analyst
Image Analyst 2017-11-11
Simply use the function meant for that. If you have the Image Processing Toolbox, use regionprops:
a = [77 77 77 79 79 79 77 77 77 77];
props = regionprops(a == 77, 'Area');
allLengths = [props.Area]
You'll get:
allLengths =
3 4

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by