limit range of loop iteration

6 ビュー (過去 30 日間)
Aamna Alshehhi
Aamna Alshehhi 2019 年 10 月 3 日
コメント済み: Jess Lovering 2019 年 10 月 3 日
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.
Aamna Alshehhi
Aamna Alshehhi 2019 年 10 月 3 日
here you go. this m file

サインインしてコメントする。

採用された回答

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 Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by