if x=0

34 views (last 30 days)
Goncalo Miguel
Goncalo Miguel on 4 May 2020
Commented: Goncalo Miguel on 4 May 2020
Hello everyone I am trying to write something like:
x=input('x value: '); y=input('y value: ');
k=x*y;
if k=6 k1=2; elseif k=0 k1=1; end
How can i write that with that statement and no error? Thank you!

Accepted Answer

James Tursa
James Tursa on 4 May 2020
Edited: James Tursa on 4 May 2020
x = input('x value: ');
y = input('y value: ');
k = x * y;
if k == 6 % <-- Use == for equality test
k1 = 2;
elseif k == 0
k1 = 1;
end
Note that there is a path for k1 to be unset if k is not 6 or 0. You might need to cover this case in your code.
  1 Comment
Goncalo Miguel
Goncalo Miguel on 4 May 2020
Thank you very much!

Sign in to comment.

More Answers (0)

Categories

Find more on Argument Definitions in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!