Index in position 2 exceeds array bounds (must not exceed 25).
Afficher commentaires plus anciens
function[spl] = tryal2(f,P,t)
if f == 40
w = 2*pi*f;
A = 10;
end
c = 343;
x = [0:.5:11];
y = [0:.5:15];
k = w/c;
[xx,yy]= meshgrid(x,y);
H = sqrt((xx-0).^2)+(yy-9).^2;
Lx = length(x);
Ly = length(y);
phasor = zeros(Lx,Ly);
Meanpressure = zeros(Lx,Ly);
spl = zeros(Lx,Ly);
for a=1:Lx
for b=1:Ly
phasor(a,b) = ((A+P)./H(a,b))*exp(1j*((w*t)-((w/c)*H(a,b))));
Meanpressure(a,b) = sqrt(0.5*phasor(a,b)*conj(phasor(a,b)));
spl(a,b)= 20*log10(Meanpressure(a,b)/(20*10^(-6)));
end
end
figure
surf(xx,yy,spl)
The error occurs in phasor(a,b) = ((A+P)./H(a,b))*exp(1j*((w*t)-((w/c)*H(a,b)))); i am confused what i am doing wrong I need a grid by 11 by 14 but i only get answers if x and y martixes are the same.
Réponses (3)
Geoff Hayes
le 26 Avr 2019
benjamin - isn't H of length Lx (or Ly since identical) and is an array? Treating it like a matrix as H(a,b) would then lead to this error. Note how
H = sqrt((xx-0).^2)+(yy-9).^2;
and so is not a matrix since xx and yy are arrays.
3 commentaires
benjamin chong
le 26 Avr 2019
Geoff Hayes
le 26 Avr 2019
well either make H a matrix or just grab H(b) on each iteration. to be honest i don't know enough about your code (i.e. what it does) to tell you what to do.
Geoff Hayes
le 27 Avr 2019
Benjamin - please provide the inputs to your function. What is f? What are P and t?
Also, please further the conversation by adding comments and not creating answers.
benjamin chong
le 26 Avr 2019
benjamin chong
le 26 Avr 2019
0 votes
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
