Creating multiple polar plot graphs for different frequencies

6 ビュー (過去 30 日間)
Cameron Latta
Cameron Latta 2019 年 10 月 19 日
回答済み: Daniel M 2019 年 10 月 19 日
Essentially trying to use a loop to generate multiple plots for different values of f.
I get this error message:
Index exceeds the number of array elements (1).
Error in PistonDirectivity_2_11 (line 21)
f = f(n);
f = [125 250 500 1000 2000 4000 8000];
%f = 3.3820e+03; %frequency
c = 340; %speed of sound at 20 degrees
rho0 = 1.2; %Acoustic impedance at 20 degrees
r = 100; %radius
a = 0.16; %piston radius
u0 = 1; %particle velocity
theta = linspace(-pi/2+1.e-16,pi/2-1.e-16,181)'; %range of theta values from 90 to -90 degrees
%p = (1j*rho0*c*k*a^2*u0/(2*r) .* 2.* besselj(1,kasintheta)./kasintheta) * exp(-1j*k*r);
n = 1;
%% loop to make multiple plots
%while n < length(f)
for n = 1 : length(f)
f = f(n);
k = 2*pi*f./c; %wavenumber
p = besselj(1, k*a.*sin(theta))./(k*a.*sin(theta));
db = 20*log10(abs(p)); %calculate dB and plot polar response
mx = max(db);
dynamic_range = 40;
db = db + dynamic_range - mx;
db = max(db,zeros(size(db)));
polar(theta,db); %plot polar response
figure %plot flat response
plot(theta,db)
xlabel('Theta (rads)')
ylabel('Level (dB)')
hold on
n = n+1;
end
  2 件のコメント
Daniel M
Daniel M 2019 年 10 月 19 日
You're overwriting f in your loop. Don't do that.
Cameron Latta
Cameron Latta 2019 年 10 月 19 日
Ahh, thank you! That seems to have fixed it! Cheers

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

採用された回答

Daniel M
Daniel M 2019 年 10 月 19 日
I'm writing the same thing here so this question can be answered.
The issue is you are overwriting your variable f when you write f = f(n). I suggest changing it inside your loop, to fn = f(n).

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by