limit range of loop iteration

7 次查看(过去 30 天)
I got this code to plot Th2 vs Th3 and Th4 but I wanna limit the range of Th2 which is " i " to (0 to 47) and (313 to 360).
also I wanna get path coordinates of point P to same range.
any suggetions?
for i=0:47;
d =3.5; a = 4;b = 2; c = 1;
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 (:,i+1) = rad2deg(angle(T));
P= a*exp(1i* deg2rad(Th2))+ 6*exp(1i* deg2rad(Th3-20));
end
Th2 = 0:47;
figure(1)
plot (Th2,Th3(1,:));
hold on;
plot (Th2,Th3(2,:));
xlabel ('TH)')
ylabel ('TH3')
figure(2)
plot (Th2,Th4(1,:));
hold on;
plot (Th2,Th4(2,:));
xlabel ('TH2') ;
ylabel ('TH4') ;
  2 个评论
David Hill
David Hill 2019-10-3
It would be nice to see the variables in a .mat file. It is hard to understand what you are trying to do here.

请先登录,再进行评论。

采纳的回答

Jess Lovering
Jess Lovering 2019-10-3
Do you mean that you want your loop to go through i = 0 to 47 and then 313 to 360? If that is what you want then you can just replace the line:
for i=0:47;
with
for i=[0:47 313:360];
Is that your goal? If not, maybe you can provide some more detail. Thanks.

更多回答(1 个)

Aamna Alshehhi
Aamna Alshehhi 2019-10-3
yeah that's what I meant. Thanks!
  2 个评论
Aamna Alshehhi
Aamna Alshehhi 2019-10-3
I did this but i got an error:
Error using plot
Vectors must be the same length.
Error in hw4_Pc (line 19)
plot (Th2,Th3(1,:));
Jess Lovering
Jess Lovering 2019-10-3
It is difficult to help since we don't have the Th2 variable. Plus, it looks like it is redefined after the loop to be 0:47 so then it is shorter than the variable Th3 that is generated in the loop. You could also define it as Th2 = 0:360 to make it the same size, but I think that may not be what you are trying to view.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by