Take the 2-minute tour ×

I'm trying to plot the following piecewise function in MATLAB:

N(e,:) = (n*x-e+1).*(x>(e-1)/n).*(x<e/n) + (-n*x+e+1).*(x>e/n).*(x<(e+1)/n);

And the result is this:


instead of an isosceles triangle as it should be. Does anybody know how to fix this or have any alternative?

share|improve this question
The given code doesn't compile. Please, provide a working piece of code. –  Mikhail Dec 22 '12 at 20:56
Done. It's taken from a larger block of code, so I apologize for the inconvenience using the 'e' and 'n' variables. –  Chuck Dec 22 '12 at 21:19

1 Answer 1

up vote 0 down vote accepted

I assume you want your function to actually have value of 1 at x=0.11 instead of value of 0. For this, you can simply replace (x<e/n) with (x<=e/n).

share|improve this answer
It works fine, thanks! –  Chuck Dec 22 '12 at 21:31

Your Answer


