필터 지우기
필터 지우기

Simple question about vector remainders

조회 수: 3 (최근 30일)
Phil
Phil 2012년 11월 28일
So I have one vector x = [19 21 25 24 18 20]
I need to use this vector to find another vector that contains only the amounts over 20. So it should look something like x = [0 1 5 4 0 0].
This seems like it should be incredibly simple but it is giving me grief. The only thing I have tried that has come relatively close is something like b = (x-20)>0 which simply returns that certain values are true to be over 20(i.e. b = 0 1 1 1 0 0.)
I've also tried declaring another vector w = [20 20 20 20 20 20] and then doing z = w - x but that returns some negative results in the vector.
Any help is greatly appreciated.

채택된 답변

Matt Fig
Matt Fig 2012년 11월 28일
편집: Matt Fig 2012년 11월 28일
y = mod(x,20).*(x>20) % if no x>40
Or if some value may be greater than 40,
y = max(x-20,0)

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 28일
편집: Azzi Abdelmalek 2012년 11월 28일
y=(x-20).*(x>20)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by