Define variable based on input condition

14 ビュー (過去 30 日間)
Jacob Curtin
Jacob Curtin 2023 年 11 月 14 日
編集済み: madhan ravi 2023 年 11 月 15 日
I have a function which calculates two possible output values (psi positive or negative) for a given input value (th2) as th2 sweeps from 0 to 360.
th2 = 0: 0.1: 360;
A = 2*a*c.*cosd(th2)-2*d*c;
B = 2*a*c.*sind(th2);
C = (d^2) + (c^2) + (a^2) - (b^2) - (2*a*d.*cosd(th2)) ;
psi_pos = (atan2d(B,A) + acosd(C ./ (sqrt((A.^2) + (B.^2)))));
psi_neg = (atan2d(B,A) - acosd(C ./ (sqrt((A.^2) + (B.^2)))));
The outputs for psi_pos and psi_neg are 1x3601 doubles,
I want a final variable psi defined as
psi_pos when 0 < th2 < 180
psi_neg when 180 < th2 < 360
So I can then plot one continuous function (psi vs th2)

採用された回答

madhan ravi
madhan ravi 2023 年 11 月 15 日
編集済み: madhan ravi 2023 年 11 月 15 日
psi = ((0 <= th2) & (th2 < 180)) .* psi_pos + ((180 <= th2) & (th2 < 360)) .* psi_neg;
plot(th2, psi)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGamma Functions についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by