Can't find sat() function

Hi, I want to use sat function (which is a saturation function) but I not sure which toolbox contains this function. Can anyone help? :) Urgent question!!!

2 Comments

Luckily, I had some free time, and your problem was easy to solve. But remember that we don't really care that your problem is urgent, and that every other person asking a question on Answers has just as much a right to hope for a timely answer to their questions as do you.
Finally, I would comment that the answer I did post was something you could have trivially found in far less time than it took you to write the question and for me to give you an answer.
Sorry about that and thanks for answering to my question :)

Sign in to comment.

Answers (1)

which sat -all
'sat' not found.
sat.m is not found in any MathWorks provided toolbox.
You may need to ask your instructor, since they may have written this code. Another possibility is that function may be found on the file exchange. So I looked there. (You could have done as easily!)
When I did so, after a looking at dozens of tools, I found this:
which does have a function named sat.m
function y=sat(x);
% sat is the saturation function with unit limits and unit slope.
if x>1
y=1;
elseif x<-1
y=-1;
else
y=x;
end
which does something with a saturation. Is that what you want? God only knows. :) well, you may know. Anyway, that function sat is actually pretty simple.

3 Comments

function y = sat(x)
%vectorized version
y = max(-1, min(1, x));
end
This is Buggy suggestion !!
x = -2147483647
x = -2.1475e+09
y = max(-1, min(1, x))
y = -1
input-value (Decimal): -2147483647
input-value (Decimal): 80000001
input-value (Decimal): 10000000000000000000000000000001
Reduced and saturated value (Decimal): 2147483647
Reduced and saturated value (Hex): 7FFFFFFF
Reduced and saturated value (Binary): 01111111111111111111111111111111
No, this suggestion is working as expected for the input you provided.
I think you're assuming that 1) x is stored in an integer type [it's not, x is a double array] and 2) MATLAB uses wrapping arithmetic for integers [it doesn't, it saturates.]
x = -2147483647
x = -2.1475e+09
class(x) % double not one of the integer types
ans = 'double'
minval = intmin('int32') % This is stored as an int32
minval = int32 -2147483648
maxval = intmax('int32')
maxval = int32 2147483647
z = minval-1 % equal to minval not maxval
z = int32 -2147483648
w = maxval+1 % equal to maxval not minval
w = int32 2147483647

Sign in to comment.

Asked:

on 17 Dec 2021

Commented:

on 2 Jul 2024

Community Treasure Hunt

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

Start Hunting!