How do I stop a code from continuing ifelse statements?

3 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by