[SOLVED] How can I execute this function for range of values?

Issue

I have this function
enter image description here
where f has values (18 19 20 21 22), and I should compute the value of the function for each value of f and plot each value.
I try to make f as vector 18:22, but it gives result from 1 to 22. Same result when I use for loop. My code is below, how can I modify it to take the values within the range only?

clc
fc=20;
theta=80;
N=16;
f=18:22;
g_m(f)=(sin((N*pi/2).*sin(theta).*(f/fc-1)))./sqrt(N).*(sin(pi/2).*(f/fc-1));
g_p(f)=exp(1j*0.5*(N-1).*pi*sin(theta).*(f/fc-1));
gain(f)=g_m(f).*g_p(f);
figure(1);
plot(f,g_m(f));

Solution

I believe this should give you enough information:

f = 5:7;
g(f)= [2, 2, 5]
g =  
   0   0   0   0   2   2   5

Answered By – CG.

Answer Checked By – David Goodson (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *