Filter löschen
Filter löschen

How do I stop a code from continuing ifelse statements?

3 Ansichten (letzte 30 Tage)
Andrew Winkle
Andrew Winkle am 9 Dez. 2015
Kommentiert: Jon am 9 Dez. 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);
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.

Akzeptierte Antwort

Jon
Jon am 9 Dez. 2015
  2 Kommentare
Andrew Winkle
Andrew Winkle am 9 Dez. 2015
Thank you, I must have been using it in the wrong line. I appreciate your quick response.
Jon
Jon am 9 Dez. 2015
Or your if condition wasn't being met. In an if statement, these two perform the same, but they behave differently in loops.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by