Create function that varies between 1 and zero if input is 1 or 2

Hello as the title explains I want to create a function that gives an output of either 1 or zero depending if the input is 1 or 2 this is what I've tried but does't seem to work:
function [y1,y2] = delt(x)
if x == 2
y1=1;
else
y2=0;
end
end

 採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 11 月 10 日
The output variable should be the same -
y1 = delt(1)
y1 = 0
y2 = delt(2)
y2 = 1
y3 = delt(-69)
y3 = 0
function y = delt(x)
if x == 2
y=1;
else
y=0;
end
end

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

製品

リリース

R2023b

タグ

質問済み:

2023 年 11 月 10 日

コメント済み:

2023 年 11 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by