Piecewise functions

Evaluate a general piecewise function of one variable
10,6K téléchargements
Mise à jour 10 avr. 2006

Afficher la licence

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])

Citation pour cette source

John D'Errico (2026). Piecewise functions (https://fr.mathworks.com/matlabcentral/fileexchange/9394-piecewise-functions), MATLAB Central File Exchange. Extrait(e) le .

Compatibilité avec les versions de MATLAB
Créé avec R14SP1
Compatible avec toutes les versions
Plateformes compatibles
Windows macOS Linux
Tags Ajouter des tags
Remerciements

A inspiré : Piecewise defined function builder

Version Publié le Notes de version
1.0.0.0

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