build an array within the loop
Show older comments
i wanna build two arrays within a loop. the first array contain Th2 elements and the second array contain Th3 elements. then i wanna plot them. this my code
for Th2=0:360
d =3.5; a = 1;b = 2; c = 4;
Th1= 0;
Z = d*exp(1i*deg2rad(Th1))- a*exp(1i*deg2rad(Th2));
Zc = conj(Z);
Ka = c*Zc; Kb = Z*Zc + c^2 -b^2; Kc = c*Z;
T = roots([ Ka Kb Kc]);
S = (c*T+Z)/b;
Th3 = rad2deg(angle(S));
Th4 = rad2deg(angle(T));
P= a*exp(1i* deg2rad(Th1))+ 6*exp(1i* deg2rad(Th3+20));
end
plot (Th2,Th3);
Accepted Answer
More Answers (1)
Ajay Kumar
on 2 Oct 2019
You are not creating Th3 array but overwriting it everytime. Try this
for i=0:360
d =3.5; a = 1;b = 2; c = 4;
Th1= 0;
Z = d*exp(1i*deg2rad(Th1))- a*exp(1i*deg2rad(i));
Zc = conj(Z);
Ka = c*Zc; Kb = Z*Zc + c^2 -b^2; Kc = c*Z;
T = roots([ Ka Kb Kc]);
S = (c*T+Z)/b;
Th3(:,i+1) = rad2deg(angle(S));
Th4 = rad2deg(angle(T));
P= a*exp(1i* deg2rad(Th1))+ 6*exp(1i* deg2rad(Th3+20));
end
Th2 = 0:360;
plot (Th2,Th3(1,:));
hold on;
plot (Th2,Th3(2,:));
1 Comment
Aamna Alshehhi
on 2 Oct 2019
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!