Trying to see if a variable is an integer or not

조회 수: 1 (최근 30일)
Gianni Davies
Gianni Davies 2021년 5월 10일
댓글: Gianni Davies 2021년 5월 11일
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
  댓글 수: 3
Gianni Davies
Gianni Davies 2021년 5월 11일
Cheers all of these work

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by