0
$\begingroup$

Hardlim matlab function should look like a step:

enter image description here

But the code provided at the documentation page

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

gives me this output:

enter image description here

$\endgroup$
2
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – murat tuna Aug 13 at 10:55
  • $\begingroup$ Isnt it a bug @jan kukacka $\endgroup$ – murat tuna Aug 13 at 11:03
  • $\begingroup$ 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]) $\endgroup$ – Jan Kukacka Aug 13 at 11:10
  • $\begingroup$ I got but finally the graphs express as an example -0.2=0.2 .Then it is bug in my opinion @jan $\endgroup$ – murat tuna Aug 13 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.