creating a function with a condition set

How do I create this function in Matlab? All of the tutorials seem to use very simple syntax in the functions.
f(t) = {

3 件のコメント

Hollie Pietsch
Hollie Pietsch 2017 年 9 月 16 日
It should show this function, but for some reason it shows blank.
f(t) = {
Walter Roberson
Walter Roberson 2017 年 9 月 16 日
Perhaps post an image of the formula.
Hollie Pietsch
Hollie Pietsch 2017 年 9 月 16 日

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 9 月 16 日
編集済み: Walter Roberson 2017 年 9 月 16 日

0 投票

If you have Symbolic Toolbox and R2016b or later, you can use piecewise
Otherwise, you need something like
function ft = f(t)
ft = nan(size(t));
mask = t >= 0 & t < 2;
ft(mask) = t(mask) - 1;
mask = t >= 2 & t < 4;
ft(mask) = 3 - t(mask);
Notice the nan: your function definition does not define any value for t outside of [0, 4) so no number can be assigned for those cases.

カテゴリ

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

質問済み:

2017 年 9 月 16 日

編集済み:

2017 年 9 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by