How to define function
4 views (last 30 days)
Show older comments
Viktoriia Buliuk
on 11 Aug 2020
Commented: Viktoriia Buliuk
on 4 Sep 2020
Hello!
Could you, please, suggest an answer:
How to define function f (x), which for x from -1 to 1, f (x) = 1; and outside these limits f (x) = 0.
Thank in advance!
3 Comments
Accepted Answer
hosein Javan
on 11 Aug 2020
function y = f(x)
y = zeros(size(x));
y(abs(x) < 1) = 1;
end
5 Comments
hosein Javan
on 11 Aug 2020
ofcourse unless you want to use function file, you need this multiplication only to define your function in anonymous form. correct.
More Answers (0)
See Also
Categories
Find more on Operators and Elementary Operations 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!