連続したある数値以上の要素を一つのグループとして表したい
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
A=[-210 -210 -33 -34 -33 -35 -30 -33 -210 -33 -33 -210 -210 -34 -36 -35 -210]
B=[6 2 3]
上のような1行n列のAがあったとして、-210より大きく連続しているもの(左から「-33 -34 -33 -35 -30 -33 」、「-33 -33」、「-34 -36 -35」)のそれぞれの要素数をBのように示したいです。
ご助言よろしくお願いします。
0 Kommentare
Antworten (2)
Hernia Baby
am 6 Jun. 2022
bwlabel 関数を使ってみてください
A=[-210 -210 -33 -34 -33 -35 -30 -33 -210 -33 -33 -210 -210 -34 -36 -35 -210];
[groups, numGroups] = bwlabel(A > -210)
for ii = 1:numGroups
B(1,ii) = sum(groups == ii);
end
B
0 Kommentare
Atsushi Ueno
am 6 Jun. 2022
A = [-210 -210 -33 -34 -33 -35 -30 -33 -210 -33 -33 -210 -210 -34 -36 -35 -210];
temp = cumsum(A > -210)
B = diff([0 temp(diff(A > -210) < 0)]) % -210より大きく連続している要素数
0 Kommentare
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!