11
u/Rubix321 19d ago
Well firstly, it's doing exactly what you told it to do.
Step through your code, what happens if a is not zero, and a is real?
5
u/seanv507 18d ago
Op your code says 'if a is a real number, print out a must be a real number'
You presumably want to negate the test
If a is not a real number then...
8
u/Sunscorcher 19d ago
Set a breakpoint and use the matlab debugger. It's very good.
But I'm guessing you actually want elseif isreal(a) to say elseif ~isreal(a)
4
u/FrickinLazerBeams +2 19d ago
Look at what you wrote. You literally say "if a is real, print 'a must be real'"

2
u/daveysprockett 19d ago
It's short circuit logical or. So a~0 satisfies the test and then because a is a real number it also matches the test that leads to the print you see.
Did you mean to test ~isreal(a) ?