Create a top hat function
102 views (last 30 days)
Hello, Im trying to create a top hat function (that is 0 everywhere except between -halfpix & halfpix). the fucll width of the top hat (2* halfpix) is symetrical about the yaxis.
i've created it based in discrete values as below but I would like it as a general function.
x = -20:0.1:20;
t = zeros(1,length(x))
t(x>=-halfpix & x<halfpix) = 1;
Rik on 28 Jun 2021
If you realize that you are marking all true locations with 1 and leaving all false as 0, you can use that to make an anonymous function that only casts you logical statement to double.