- Use element-by-element operators such as .* because you are going to be multiplying and dividing non-scalars
- Use a row vector for one of the variables and a column vector for the other one, and starting R2015b MATLAB will automatically expand that into grids of calculations. If you are using an earlier version, you would want to use meshgrid() to make theta and freq 2D grids of values.
How to write a function in MATLAB?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
mariam muner
el 11 de Feb. de 2022
Respondida: Walter Roberson
el 11 de Feb. de 2022
Hello
i need to write this function using matlab
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/891350/image.png)
where theta takes the range of values ( 0 to 80 step 1) and the frequncy (f) take the values (18 to 22 ) and the other parameters are fixed
then i need to plot the result with the values of frequency (x-axis include the frequency and y-axis include the G)
i tried to execute it for one values of (theta and f) using this code
gain_mag=sin(N*pi/2*sin(theta)*(freq/fc-1))/sqrt(N)*sin(pi/2*sin(theta)*(freq/fc-1));
gain_phase=exp(j*0.5*(N-1)*pi*sin(theta)*(freq/fc-1));
gain=gain_mag*gain_phase;
plot(gain);
grid on;
how can i execute it for different values of theta and f?
0 comentarios
Respuesta aceptada
Walter Roberson
el 11 de Feb. de 2022
theta = (0:80).'; %column vector
freq = 18:22; %row vector
gain_mag = sin(pi/2 .* N .* sin(theta) .* (freq/fc-1)) ./ sqrt(N) .* sin(pi/2 .* sin(theta) .* (freq/fc-1));
gain_phase = exp(1j*pi/2 .* (N-1) .* sin(theta) .* (freq/fc-1));
gain = gain_mag .* gain_phase;
surf(freq, theta, gain)
There are two tricks here:
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!