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.

 Akzeptierte Antwort

Jos (10584)
Jos (10584) am 3 Mär. 2016

0 Stimmen

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 Kommentar

Nishantha Randunu
Nishantha Randunu am 3 Mär. 2021
anoymous function should be
minmax = @(x,a,b) min(max(x,a),b) % restricts input X between a and b

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 3 Mär. 2016

0 Stimmen

min(max(x, -1), 1)

2 Kommentare

Susan Arnold
Susan Arnold am 3 Mär. 2016
Bearbeitet: Susan Arnold am 3 Mär. 2016
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 !!!
Simply replace -1 and 1 by the minimum and maximum of B
... max(A,min(B(:))) ...

Melden Sie sich an, um zu kommentieren.

Kategorien

Produkte

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by