Trying to see if a variable is an integer or not

1 次查看(过去 30 天)
x=2.5;
isaninteger = @(x)isfinite(x)
x=floor(x)
answer=isaninteger(x)
I want the answer here to show that x is not an integer but all it shows is answer = 1. No idea how to fix this
The correct output here would be answer = 0

采纳的回答

per isakson
per isakson 2021-5-10
编辑:per isakson 2021-5-10
Try this
%%
x=2.5;
answer = ( x == floor(x) )
answer = logical
0

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by