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

25 visualizaciones (últimos 30 días)
Keito Endo
Keito Endo el 23 de Oct. de 2021
Respondida: Atsushi Ueno el 23 de Oct. de 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の部分を簡略化できないでしょうか?

Respuesta aceptada

Atsushi Ueno
Atsushi Ueno el 23 de Oct. de 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

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!