How to define function

6 views (last 30 days)
Viktoriia Buliuk
Viktoriia Buliuk on 11 Aug 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
KSSV
KSSV on 11 Aug 2020
Show us your code.

Sign in to comment.

Accepted Answer

hosein Javan
hosein Javan on 11 Aug 2020
function y = f(x)
y = zeros(size(x));
y(abs(x) < 1) = 1;
end
  5 Comments
Viktoriia Buliuk
Viktoriia Buliuk on 4 Sep 2020
Thank you very much!

Sign in to comment.

More Answers (0)

Categories

Find more on Function Creation in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!