特定の範囲を除外する方法

2 views (last 30 days)
yuma yasuda on 11 Nov 2022
Commented: Atsushi Ueno on 11 Nov 2022

Atsushi Ueno on 11 Nov 2022
A = [ 10, 11, 12, 13, 9, 14, 15, 2, 16, 3, 17, 5, 18] ⇒ 最小値は 2
A = [ 10, 11, 12, 13, 9, 14, 15, 2, 16, 3, 17, 5, 18] ⇒ 最小値は 5
A = [ 10, 11, 12, 13, 9, 14, 15, 2, 16, 3, 17, 5, 18] ⇒ 最小値は 9

それとも
A = [ 10, 11, 12, 13, 9, 14, 15, 2, 16, 3, 17, 5, 18] ⇒ 最小値は 2
A = [ 10, 11, 12, 13, 9, 17, 5, 18] ⇒ 最小値は 5
A = [ 10, 11, 12, 13] ⇒ 最小値は 10

また、除外される数値に次の最小要素が含まれいた場合でも除外すると認識しています。

Atsushi Ueno on 11 Nov 2022
Edited: Atsushi Ueno on 11 Nov 2022

A = [ 10, 11, 12, 3, 4, 9, 11, 2, 10, 13, 11, 5, 9]
A = 1×13
10 11 12 3 4 9 11 2 10 13 11 5 9
for k = 1:3
idx = find(A == min(A));
A(max(1,idx-2):min(idx+2,numel(A))) = inf
end
A = 1×13
10 11 12 3 4 Inf Inf Inf Inf Inf 11 5 9
A = 1×13
10 Inf Inf Inf Inf Inf Inf Inf Inf Inf 11 5 9
A = 1×13
10 Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf
2 3 5
yuma yasuda on 11 Nov 2022

Categories

Find more on 行列および配列 in Help Center and File Exchange

R2022a

Community Treasure Hunt

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

Start Hunting!