필터 지우기
필터 지우기

Create a top hat function

조회 수: 30 (최근 30일)
Jason
Jason 2021년 6월 28일
댓글: Jason 2021년 6월 28일
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
Rik 2021년 6월 28일
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.
  댓글 수: 5
Rik
Rik 2021년 6월 28일
You already know how to do that. You already used the code in your own question:
t=@(x) double(x>=-halfpix & x<halfpix)
Jason
Jason 2021년 6월 28일
Perfect, thankyou

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by