Piecewise functions

版本 1.0.0.0 (2.1 KB) 作者: John D'Errico
Evaluate a general piecewise function of one variable
10.6K 次下载
更新时间 2006/4/10

查看许可证

Would you like to be able to specify a piecewise
function? For example, piecewise_eval can do this:

x < -5, y = 2
-5 <= x < 0, y = sin(x)
0 <= x < 2, y = x.^2
2 <= x < 3, y = 6
3 <= x, y = inf

y = piecewise_eval(-10:10,[-5 0 2 3], ...
{2,'sin(x)','x.^2',6,inf})

Plot a top hat function with ezplot?
ezplot(@(x) piecewise_eval(x,[0 1],{0 1 0}),[-1 2])

引用格式

John D'Errico (2024). Piecewise functions (https://www.mathworks.com/matlabcentral/fileexchange/9394-piecewise-functions), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R14SP1
兼容任何版本
平台兼容性
Windows macOS Linux
标签 添加标签
致谢

启发作品: Piecewise defined function builder

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0.0

Fixed it so it now should work on older releases, as long as you supply inline functions.