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)

回答 (3 件)

Erivelton Gualter
Erivelton Gualter 2019 年 5 月 6 日

2 投票

You can use the following line of code:
X = @(om) (1*(abs(om)==1) + 0*(abs(om)~=1));
NIMMALA HARATHI
NIMMALA HARATHI 2020 年 5 月 23 日

0 投票

[X, lambda] = eig(A)
saideh zare
saideh zare 2021 年 7 月 4 日

0 投票

Unrecognized function or variable 'lambda'.

カテゴリ

製品

リリース

R2019a

質問済み:

2019 年 5 月 6 日

回答済み:

2021 年 7 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by