Unable to find function @(fd)(1/(1​+A(fd/fdma​x2)^2)) within E:\matlab\bin\hw3.m.

Why there is error : Unable to find function @(fd)(1/(1+A(fd/fdmax2)^2)) within E:\matlab\bin\hw3.m. ???
%Model B
v=1200;
c=3e8;
f2=2.4e9;
f5=5.25e9;
%For 2,4 GHz
fmax2=v*f2/c;
fdmax2=fmax2/5;%Doppler spread
Tc2=1/fdmax2;%Coherrence time for 2 GHz
A=9;
%For 5.25 GHz
fmax5=v*f5/c;
fdmax5=fmax5/5;%Doppler spread
Tc5=1/fdmax5;%Coherrence time for 5.25 GHz
%Plot Doppler sprectrum for Model B, 2 GHz
fd=(-fmax2).*rand(1000,1)+fmax2;
plot(Phih_B_2(fd),fd)
Unrecognized function or variable 'Phih_B_2'.
function Phih_B_2=g2(fd)
Phih_B_2=(1/(1+A(fd/fdmax2)^2));
end

 Accepted Answer

As you can see, the error here is different than what you report.
Did you consider changing your function to have an output argument, and to make sure it doesn't attempt to create a variable with the same name as the function?
There are more issues with your function:
  • You are providing a vector as input, but you don't use element-wise operations.
  • You don't provide A or fdmax2 as input arguments.
  • You attempt to index A, but it is a scalar (and the indices are unlikely to be positive integers).

4 Comments

As I understand variable name in function should be the same as function name.
Which element-wise operation should I use for vector as input of function??
I added input arguments (A and fdmax2) and added operator * for A
plot(Phih_B_2(fd,A,fdmax2),fd)
function Phih_B_2=g2(fd,A,fdmax2)
Phih_B_2=(1/(1+A*(fd./fdmax2)^2));
end
If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks).
You're close. You should call your function by the function name, not the output argument name. And if you want element-wise operations, you need to add periods for every operation involving arrays:
plot(g2(fd,A,fdmax2),fd)
function Phih_B_2=g2(fd,A,fdmax2)
Phih_B_2 = 1./(1+A*(fd./fdmax2).^2);
end

Sign in to comment.

More Answers (0)

Categories

Find more on Detection, Range and Doppler Estimation in Help Center and File Exchange

Products

Release

R2020b

Tags

Asked:

on 24 May 2023

Commented:

Rik
on 25 May 2023

Community Treasure Hunt

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

Start Hunting!