MATLAB: In an assignment A(I) = B, the number of elements in B and I must be the same.

arrayfor loop

My for Loop performs three iteration and then I get this error "In an assignment A(I) = B, the number of elements in B and I must be the same"
rho = 1.21; c = 343; c2 = c^2; V = 1+0*1i; Qb = 1/(sqrt(2));
Vas = 0.008778;
Sd = 0.0062;
Sd2 = Sd^2;
Qm = 1.4; Qe = 0.47; Qt = 0.35; Ro = 7.4;
fs = 70;
S = (rho*c2*Sd2)/(Vas);
m = (S)/(4*pi^2*fs^2);
Bl = sqrt((Ro*S)/(Qe*2*pi*fs));
Rm = S/(Qm*2*pi*fs);
Vc = Vas*((1)/(((1/(sqrt(2)*Qt))^2)-1));
Sc = (rho*c2*Sd2)/(Vc);
f3 = (sqrt((S+Sc)/m))*(1/(2*pi));
N = 500; ws =1; we = N*2*pi;
r = 1;
for w = ws:1:we
%%Pressure Amplitude
Parray(w)= (rho/(4*pi*r))*((Sd*Bl)/(Ro*m))*(((1i*w).^2)/(((1i*w.^2)+(((2*pi*f3)/Qb)*(1i*w))+(2*pi*f3).^2)))*(abs(V));
P(w)= abs(Parray(w))
%%Velocity Amplitude
Varray(w) = (Bl/Ro)/((w*m*1i)+(Rm)+((Bl^2)/Ro)+(S/(1i*w))+((rho*c2*Sd2)/(Vc*1i*w)))*(V);
V(w) = abs(Varray(w))
%%Displacement Amplitude
Xarray(w) = (Varray(w))/(1i*w);
X(w) = abs(Xarray(w))
end
semilogx(P)
Not sure what size to worry abot. Thanks in advance

Best Answer

rho = 1.21; c = 343; c2 = c^2;
V = 1+0*1i;
Qb = 1/(sqrt(2));
Vas = 0.008778;
Sd = 0.0062;
Sd2 = Sd^2;
Qm = 1.4;
Qe = 0.47;
Qt = 0.35;
Ro = 7.4;
fs = 70;
S = (rho*c2*Sd2)/(Vas);
m = (S)/(4*pi^2*fs^2);
Bl = sqrt((Ro*S)/(Qe*2*pi*fs));
Rm = S/(Qm*2*pi*fs);
Vc = Vas*((1)/(((1/(sqrt(2)*Qt))^2)-1));
Sc = (rho*c2*Sd2)/(Vc);
f3 = (sqrt((S+Sc)/m))*(1/(2*pi));
N = 500;
ws =1;
we = N*2*pi;
r = 1;
for w = ws:1:we
% Pressure Amplitude
Parray(w)= (rho/(4*pi*r))*((Sd*Bl)/(Ro*m))*(((1i*w).^2)/(((1i*w.^2)+(((2*pi*f3)/Qb)*(1i*w))+(2*pi*f3).^2)))*(abs(V(w))); %Line1 corrected
P(w)= abs(Parray(w));
% Velocity Amplitude
Varray(w) = (Bl/Ro)/((w*m*1i)+(Rm)+((Bl^2)/Ro)+(S/(1i*w))+((rho*c2*Sd2)/(Vc*1i*w)))*(V(w));
V(w+1) = abs(Varray(w)); % line2 corrected
% Displacement Amplitude
Xarray(w) = (Varray(w))/(1i*w);
X(w) = abs(Xarray(w));
end
semilogx(P)
%Lines corrected 25 V(w) instead V and 29: V(w+1) instead V
Related Question