Trying to see if a variable is an integer or not
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Gianni Davies
il 10 Mag 2021
Commentato: Gianni Davies
il 11 Mag 2021
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
0 Commenti
Risposta accettata
per isakson
il 10 Mag 2021
Modificato: per isakson
il 10 Mag 2021
Try this
%%
x=2.5;
answer = ( x == floor(x) )
3 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!