필터 지우기
필터 지우기

How to limit a vector to a certain maximum

조회 수: 74 (최근 30일)
Phil
Phil 2012년 11월 29일
댓글: Bill Tubbs 2021년 5월 6일
I have the vector x = [20 19 23 24 17] and I want to somehow create a vector that contains nothing greater than 20. That is, I need a vector that returns y = [20 19 20 20 17] from the original vector. The methods I have tried only return some sort of a boolean type vector that tells me which values are greater than 20. Can anyone help me?
  댓글 수: 1
Bill Tubbs
Bill Tubbs 2021년 5월 6일
See this answer which provides a simple function to do this.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2012년 11월 29일
xMax = 20;
x = [20 19 23 24 17]
% Clip to xMax
x(x>xMax) = xMax
  댓글 수: 5
James Pieris
James Pieris 2020년 9월 5일
Hi, do you think you can reference the matlab feature x (x> xmax) from which you derived this technique? I am just interested to know where this defined/listed in matlab documentation. Thanks a lot. it works.
Image Analyst
Image Analyst 2020년 9월 6일
Do a search in the help for "logical indexing".

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by