How to restrict the range ?
32 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
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
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
2016 年 3 月 3 日
min(max(x, -1), 1)
2 件のコメント
Jos (10584)
2016 年 3 月 4 日
Simply replace -1 and 1 by the minimum and maximum of B
... max(A,min(B(:))) ...
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!