同じ値が連続する場合の条件

12 vues (au cours des 30 derniers jours)
Keito Endo
Keito Endo le 23 Oct 2021
不連続に増加している行列で
「n-10~nが同じ値」 かつ 「n~n+5がすべて異なる」n~n+10を抽出したいです。
a = [1 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20].'
の [4 5 6 7 8 9 10 11 12 13] を抜き出したい。 
for n = 10:length(a)-5
if a(n,1)==a(n-1,1)&&a(n,:)==a(n-2,1)、、、&&a(n,:)==a(n-10,1)&&a(n,1)~=a(n+1,1)、、&&a(n,1)~=a(n+5,1)
そこで上記の条件式を組んだのですが、ifの部分を簡略化できないでしょうか?

Réponse acceptée

Atsushi Ueno
Atsushi Ueno le 23 Oct 2021
行列値のパターン検索(変化無が10文字連続+変化有が5文字連続)に文字列検索のstrfindを使いました。
a = [1 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20].';
position = strfind(~~diff(a'), [zeros(1,10) ones(1,5)]);
a(position + 10:position + 19)'
ans = 1×10
4 5 6 7 8 9 10 11 12 13

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!