Normalized Sinc using matrix inputs

2 ビュー (過去 30 日間)
Eric Brown
Eric Brown 2022 年 4 月 5 日
コメント済み: Eric Brown 2022 年 4 月 5 日
My code is to use the formula sinc(x) = sin(x*pi)/(x*pi) to return a matrix of the same size as the input, and when dealing with a element equal to zero, it is to return a value of one.
function y = normsinc(vec)
y = sin(vec)*pi ./ (vec*pi);
This is what I have right now, but it can't use if statement to check the values of the input. I get the same size output as the input but for zeros I get NaN.
  2 件のコメント
Jan
Jan 2022 年 4 月 5 日
" but it can't use if statement to check the values of the input." - why not?
Eric Brown
Eric Brown 2022 年 4 月 5 日
Its school work and they have 'tests' to check that the code follows their guidelines.

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2022 年 4 月 5 日
What about appending:
y(isnan(y)) = 1;

カテゴリ

Help Center および File ExchangeNaNs についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by