- 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 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Walter Roberson
2022 年 2 月 11 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!