"Undefined function or variable 'y'"
Show older comments
Here is my code.
x = 1:100 (Creating a vector from 1-100)
if rem(x,2) == 0 (looking for even numbers)
y = x
end
y
Why is it telling me that y is undefined. It's essentially skipping over my if statement
Accepted Answer
More Answers (1)
amin ya
on 8 Oct 2018
If your condition doesn't hold true., it will skip your if, and it will give an error when you recall y.
You can get the output of y by not puting ";" in front of the y=x. You can also use "else"
if rem(x,2) == 0 (looking for even numbers)
y = x
else
y='not defined'
end
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!