HOW DO I DO THAT IN MATLAB SERIES?

In this series, I am answering questions that students have asked me about MATLAB.

Contents

TOPIC

How do I check if a number is a integer or decimal number

SUMMARY

Language : Matlab 2010a; Authors : Autar Kaw and Sri Harsha Garapati; Mfile available at Last Revised : January 23, 2012; Abstract: This program shows you how to check if a number is an integer or decimal number using if-else-end statement in MATLAB

clc
clear all

INTRODUCTION

disp('ABSTRACT')
disp('   This program shows you how to check if a number is an integer or')
disp('    or decimal number using if-else-end statement in MATLAB')
disp(' ')
disp('AUTHOR')
disp('   Autar Kaw and Sri Harsha Garapati of http://autarkaw.wordpress.com')
disp(' ')
disp('MFILE SOURCE')
disp('   http://numericalmethods.eng.usf.edu/blog/integer_or_decimal_ex2_ch19_ifelse_end_blog.m')
disp(' ')
disp('LAST REVISED')
disp('   February 13, 2012')
disp(' ')
ABSTRACT
   This program shows you how to check if a number is an integer or
    or decimal number using if-else-end statement in MATLAB
 
AUTHOR
   Autar Kaw and Sri Harsha Garapati of http://autarkaw.wordpress.com
 
MFILE SOURCE
   http://numericalmethods.eng.usf.edu/blog/integer_or_decimal_ex2_ch19_ifelse_end_blog.m
 
LAST REVISED
   February 13, 2012
 

INPUTS

% number to check, innum
innum=13.5;

DISPLAYING INPUTS

disp('  ')
disp('INPUTS')

% Printing the input number
fprintf('The input number to be tested is %g\n',innum)
  
INPUTS
The input number to be tested is 13.5

CODE AND DISPLAYING OUTPUT

disp('  ')
disp('OUTPUTS')

% method  - using the if-else-end
if ceil(innum)==innum
    disp('  This number is an integer')
else
    disp('  This number is a decimal')
end
  
OUTPUTS
  This number is a decimal