How do I stop a code from continuing ifelse statements?

2 ビュー (過去 30 日間)
Andrew Winkle
Andrew Winkle 2015 年 12 月 9 日
コメント済み: Jon 2015 年 12 月 9 日
I'm creating a script that converts phasor to complex numbers and then back again once I'm done converting. However if I only have one phasor to convert the script runs until the very end. How do I end the whole script if it satisfies what the user wants to do with it. For instance, if a==1 I want it to do the conversion then finish.
Mag1=input('What is the magnitude in the frequency domain? ');
Angle1=input('What is the angle in the frequency domain? ');
x=Mag1*cosd(Angle1)+Mag1*sind(Angle1)*1i
mag=abs(x);
rad=angle(x);
%z=complex(x)
disp('Enter 1 for yes, 0 for no')
a=input('Are you done converting from phasor to complex?' );
if a==1
mag=abs(x)
rad=angle(x);
deg=rad*180/pi
elseif a==0
Mag2=input('What is the second magnitude?' )
Angle2=input('What is the second angle? ' )
x1=Mag2*cosd(Angle2)+Mag2*sind(Angle2)*1i
mag=abs(x1);
rad=angle(x1);
%z=complex(x)
end
b=input('Are you done coverting now? ');
if b==1
c=input('Would you like to add the two complex numbers together? ' );
if c==1
z=x+x1
elseif c==0
z=x
Thank you for any suggestions you may have.

採用された回答

Jon
Jon 2015 年 12 月 9 日
  2 件のコメント
Andrew Winkle
Andrew Winkle 2015 年 12 月 9 日
Thank you, I must have been using it in the wrong line. I appreciate your quick response.
Jon
Jon 2015 年 12 月 9 日
Or your if condition wasn't being met. In an if statement, these two perform the same, but they behave differently in loops.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by