Creating multiple polar plot graphs for different frequencies
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Cameron Latta
le 19 Oct 2019
Réponse apportée : Daniel M
le 19 Oct 2019
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 commentaires
Réponse acceptée
Daniel M
le 19 Oct 2019
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!