# How do I stop a code from continuing ifelse statements?

10 views (last 30 days)
Andrew Winkle on 9 Dec 2015
Commented: Jon on 9 Dec 2015
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);
%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)
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);
%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 on 9 Dec 2015
##### 2 CommentsShowHide 1 older comment
Jon on 9 Dec 2015
Or your if condition wasn't being met. In an if statement, these two perform the same, but they behave differently in loops.

### Community Treasure Hunt

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

Start Hunting!

Translated by