lambda function with if statement

How do I make the following function work for X. I want to be able to write lambda functions with an if clause.
X = @(om) (if abs(om)<1; 1; else 0; end)

Answers (3)

You can use the following line of code:
X = @(om) (1*(abs(om)==1) + 0*(abs(om)~=1));
saideh zare
saideh zare on 4 Jul 2021
Unrecognized function or variable 'lambda'.

Products

Release

R2019a

Asked:

on 6 May 2019

Answered:

on 4 Jul 2021

Community Treasure Hunt

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

Start Hunting!