How to get specific value?

조회 수: 2 (최근 30일)
Justyna Slawska
Justyna Slawska 2016년 12월 19일
댓글: Andrei Bobrov 2016년 12월 19일
A = [5 2 3 8 7 1 2 2 3]
[labeledA, numRegions] = bwlabel(A < 4)
% Get the size of the regions.
props = regionprops(labeledA, 'Area')
elementCounts = [props.Area]
In the command window:
A =
5 2 3 8 7 1 2 2 3
labeledA =
0 1 1 0 0 2 2 2 2
numRegions =
2
props =
2×1 struct array with fields:
Area
elementCounts =
2 4
And I get sth like this:
elementCounts =
2 4
value =
2 3 1 2 2 3

채택된 답변

Andrei Bobrov
Andrei Bobrov 2016년 12월 19일
One way:
A = [5 2 3 8 7 1 2 2 3]';
b = A < 4;
ii = bwlabel(b);
elementCounts = accumarray(ii(ii>0),1)
value = A(b)
  댓글 수: 2
Justyna Slawska
Justyna Slawska 2016년 12월 19일
how to get value when elementCounts==1 (only 1)
Andrei Bobrov
Andrei Bobrov 2016년 12월 19일
out = A(find(elementCounts == 1) == ii)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by