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

9 次查看(过去 30 天)
Keito Endo
Keito Endo 2021-10-23
回答: Atsushi Ueno 2021-10-23
不連続に増加している行列で
「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の部分を簡略化できないでしょうか?

采纳的回答

Atsushi Ueno
Atsushi Ueno 2021-10-23
行列値のパターン検索(変化無が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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!