creating a function with a condition set
9 次查看(过去 30 天)
显示 更早的评论
How do I create this function in Matlab? All of the tutorials seem to use very simple syntax in the functions.
f(t) = {
3 个评论
回答(1 个)
Walter Roberson
2017-9-16
编辑:Walter Roberson
2017-9-16
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Vehicle Scenarios 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
