# Matlab hardlim (step) function does not have exact step

Hardlim matlab function should look like a step:

But the code provided at the documentation page

n = -5:0.1:5;
a = hardlim(n);
plot(n,a)


gives me this output:

The error you see is caused by the plotting: You sample the function from $$-5$$ to $$5$$ with step size $$0.1$$, and plot these values.

...
-0.2 => 0
-0.1 => 0
0   => 1
0.1 => 1
...


Plotting module then connects these points with a line that looks exactly like your image.

• I understood but ıf you show this graph a pupil he will say different. Already math formula and math graphs isnt common? I think this is matlab's error. Thanks for editing and answer. – murat tuna Aug 13 '19 at 10:55
• Isnt it a bug @jan kukacka – murat tuna Aug 13 '19 at 11:03
• It is not a bug. This is how plot works: You give it (x,y) coordinates and it draws a line going through them. If you want to plot the step function exactly (i.e. draw the step line), you need to give it corresponding coordinates: plot([-1,0,0,1], [0,0,1,1]) – Jan Kukacka Aug 13 '19 at 11:10
• I got but finally the graphs express as an example -0.2=0.2 .Then it is bug in my opinion @jan – murat tuna Aug 13 '19 at 16:02