Piecewise functions
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])
Citar como
John D'Errico (2025). Piecewise functions (https://es.mathworks.com/matlabcentral/fileexchange/9394-piecewise-functions), MATLAB Central File Exchange. Recuperado .
Compatibilidad con la versión de MATLAB
Compatibilidad con las plataformas
Windows macOS LinuxEtiquetas
Agradecimientos
Inspiración para: Piecewise defined function builder
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Descubra Live Editor
Cree scripts con código, salida y texto formateado en un documento ejecutable.
| Versión | Publicado | Notas de la versión | |
|---|---|---|---|
| 1.0.0.0 | Fixed it so it now should work on older releases, as long as you supply inline functions. |
