How to get specific value?

1 visualizzazione (ultimi 30 giorni)
Justyna Slawska
Justyna Slawska il 19 Dic 2016
Commentato: Andrei Bobrov il 19 Dic 2016
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

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 19 Dic 2016
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 Commenti
Justyna Slawska
Justyna Slawska il 19 Dic 2016
how to get value when elementCounts==1 (only 1)
Andrei Bobrov
Andrei Bobrov il 19 Dic 2016
out = A(find(elementCounts == 1) == ii)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by