Resolving Parse/Undefined Errors

3 ビュー (過去 30 日間)
John Lynch
John Lynch 2020 年 12 月 16 日
回答済み: Aman Vyas 2020 年 12 月 23 日
The last error I'm getting for a school project. When I run code to adjust the values of an input array, it returns a message stating that 'omega' and 'h' are undefined functions or variables. I haven't run into this before, mostly because MatLab hasn't ever had an issue with parsing or giving a variable type to any of my lines. I'm wondering if it may occur with the for loop, once 'omega' and 'h' are remedied. Does anyone know how to address this?
function y = Filter(u)
c = 343; % m/s
f = 1000; % Hz
omega = 2 * pi * f;
j = sqrt(-1);
h = ifft(sqrt(j * omega / c));
x_s = 0;
for i = 1:length(u)
u(i) = (1 / (2 * pi)) * u(i) * h * (x_0 / (abs(x_0 - x_s)^2));
% we will be implementing the phase delay my adding empty samples on
% the beginning of the sample array
end
y = u;
All help is most appreciated.
  2 件のコメント
Matt Gaidica
Matt Gaidica 2020 年 12 月 17 日
The only thing I see undefined is x_0. Note that Filter is reserved in MATLAB, and j should be predefined. Post the actual line of code and specific errors if you are still having trouble.
John Lynch
John Lynch 2020 年 12 月 17 日
Thanks for the tip on j (it reccommended changing to 1i). I added the x_0 assignment as 'value', which is what I'm labelling the slider control linked to the script. However, the error is still occurring. Forgive me if this is lengthy...

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

回答 (1 件)

Aman Vyas
Aman Vyas 2020 年 12 月 23 日
Hi,
I ran the part of the code from my end and for me omega is not undefined and also h is properly defined. I think issue might be coming from some u value which is coming from some other piece of code.
Attached is the screesnshot of values read properly in the window and working fine.
Hope it helps !

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by