二値の配列の中で、同じ値が任意の点数分、連続する位置を検出するにはどうすればいいですか?
Mostra commenti meno recenti
0,1のみからなる1×n の行列 x に対して、0から1へ変化した後、1が100個以上続くような点を計算するにはどうすればよいか、教えてください。
Risposta accettata
Più risposte (1)
予め1が100個続く1×100の行列 y を用意しておいて、1×n の行列 x に対する畳み込みの結果を得る事で、1が100個以上続くような点が判ります。(100個は長過ぎるので、例として上記回答と同じ5個にしました)
x = [1 0 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 0 1 1]
y = ones(1, 5)
z = conv(x, y)
end_idx = find(z>=5) % 7番目、8番目、9番目の時点で1が5点以上続いている
start_idx = end_idx - (5 - 1) % 長さ-1を減算し開始位置のインデックスにする
Categorie
Scopri di più su パルスと遷移の計量 in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!