Can't find sat() function
Show older comments
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
John D'Errico
on 17 Dec 2021
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.
Jennie Leong
on 18 Dec 2021
Answers (1)
which sat -all
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
Walter Roberson
on 18 Dec 2021
function y = sat(x)
%vectorized version
y = max(-1, min(1, x));
end
This is Buggy suggestion !!
x = -2147483647
y = max(-1, min(1, x))
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
class(x) % double not one of the integer types
minval = intmin('int32') % This is stored as an int32
maxval = intmax('int32')
z = minval-1 % equal to minval not maxval
w = maxval+1 % equal to maxval not minval
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!