how can i define a piecewise function in matlab

1 Ansicht (letzte 30 Tage)
basem ibrahim
basem ibrahim am 12 Okt. 2012
how i define a function like this h=0 when x-w/2<=d<=x+w/2 h=1 otherwise

Antworten (1)

Sean de Wolski
Sean de Wolski am 12 Okt. 2012
Use logical indexing, for this case, you don't even need to apply the logical indices:
h = ~(x-w/2 <= d & d <= x+w/2);

Kategorien

Mehr zu Elementary Math finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by