You are on page 1of 4

Numeric Classes

Creating Integer Data


For example, to store 325 as a 16-bit signed integer assigned to variable x, type

x = int16(325);
x = 325.499; x = x + .001;

>>int16(x) >>int16(x)
ans = ans =
325 326

x = 325.5;

>>int16(fix(x))
ans =
325

11
>>int16(325) * 4.39
ans =
1427

str = 'Hello World';

>>int8(str)
ans =
72 101 108 108 111 32 87 111 114 108 100

Largest and Smallest Values for Integer Classes

You can also obtain these values with the intmax and intmin functions:

>>intmax('int8') >>intmin('int8')
ans = ans =
127 -128

>>x = int8(100) * 3 >>x = int8(-100) * 3


x= x=
127 -128

>>c = 'uppercase' - 32;

>>class(c)
ans =
double

>>char(c)
ans =
UPPERCASE

Display Format Examples


Check the current format setting:

>>get(0, 'format')
ans =

12
short

Set the value for x and display in 5-digit scaled fixed point:

>>x = [4/3 1.2345e-6]


x=
1.3333 0.0000

Set the format to 5-digit floating point:

>>format short e
x
x=
1.3333e+000 1.2345e-006

Set the format to 15-digit scaled fixed point:

>>format long
x
x=
1.33333333333333 0.00000123450000

Set the format to 'rational' for small integer ratio output:

>>format rational
x
x=
4/3 1/810045

Set an integer value for x and display it in hexadecimal (base 16) format:

>>format hex
x = uint32(876543210)
x=
343efcea

13
Basic matlab functions
Plotting functions

(i) plot

(ii) stem

(iii) subplot

(iv) xlabel

(v) ylabel

(vi) title

(vii) bar

14

You might also like