필터 지우기
필터 지우기

How to restrict the range ?

조회 수: 32 (최근 30일)
Susan Arnold
Susan Arnold 2016년 3월 3일
댓글: Nishantha Randunu 2021년 3월 3일
I want to restrict the output of the arc cosine to be in the range [-1,1], but I want to know if there is built-in Matlab function for this task and if it is possible for example merge @max & @min simultaneoulsy in the function bsxfun to achieve this task.

채택된 답변

Jos (10584)
Jos (10584) 2016년 3월 3일
I do not see why you need bsxfun for this. If X is your signal, this statement restricts X between -1 and 1
X = [0.5 1 2 -2 -1 -0.5 0]
OUT = min(max(X,-1),1)
You can create an (anonymous) function for this, if you need it a lot.
minmax = @(x,a,b) max(min(x,a),b) % restricts input X between a and b
  댓글 수: 1
Nishantha Randunu
Nishantha Randunu 2021년 3월 3일
anoymous function should be
minmax = @(x,a,b) min(max(x,a),b) % restricts input X between a and b

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2016년 3월 3일
min(max(x, -1), 1)
  댓글 수: 2
Susan Arnold
Susan Arnold 2016년 3월 3일
편집: Susan Arnold 2016년 3월 3일
What if I have two matrices which have the same size (let's say 1000 * 3), but I want for example matrix A has the same range of matrix B. What should I do to achieve this, could you please further help ?
Note: Both of these matrices have been generated randomely !!!
Jos (10584)
Jos (10584) 2016년 3월 4일
Simply replace -1 and 1 by the minimum and maximum of B
... max(A,min(B(:))) ...

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

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by