2 - Data Types - 1
2 - Data Types - 1
2 - Data Types - 1
DATA TYPES - 1
WEEK 2
NUMERIC DATA TYPES
MATLAB provides several options for storing numbers as bits (default : double)
Type Description Range
uint8 8 bit unsigned integer Integers from 0 to 255
int8 8 bit signed integer Integers from -128 to 127
uint16 16 bit unsigned integer Integers from 0 to 65535
int16 16 bit signed integer Integers from -32768 to 32767
uint32 32 bit unsigned integer Integers from 0 to 4294967295
int32 32 bit signed integer Integers from -2147483648 to 2147483647
-3.402823E38 to -1.401298E-45
single 32 bit floating point
1.401298E-45 to 3.402823E38
-1.79769313486232E308 to -4.94065645841247E-324
double 64 bit floating point
4.94065645841247E-324 to 1.79769313486232E308
STRINGS IN MATLAB
[I,J] = find(X) returns the row and column indices instead of linear indices into X.
>> A = [1, 0, 5; 0, 11, 0; 17, 0, 23]
>> [I, J] = find(A)
I=
1
3
2
1
3
J=
1
1
2
3
3
SOME ARRAY FUNCTIONS
[I,J,V] = find(X) also returns a vector V containing the values that correspond to the row and column indices I and J.
length: Computes either the number of elements of A if A is a vector or the largest value of m or n if A is an m × n matrix.
Syntax: I = length(A)
>> A = [1, 3, 5; 7, 11, 13]
>> length(A)
ans =
3
max: Largest component. For vectors, max(X) is the largest element in X. For matrices, max(X) is a row vector containing
the maximum element from each column.
Syntax: [Y,I] = max(X) returns the indices of the maximum values in vector I.
>> max(A)
ans =
7 11 13
>> x = [11, 13, 17, 19, 23]
>> max(x)
ans =
23
SOME ARRAY FUNCTIONS
size: Returns a row vector [m n] containing the sizes of the m x n array A.
Syntax: size(A)
>> A = [1, 3, 5; 7, 11, 13]
>> size(A)
ans =
2 3
sort: Sorts each column of the array A in ascending order and returns an array the same size as A.
Syntax: sort(A)
>> sort(A)
ans =
1 3 5
7 11 13
sum: Sorts each column of the array A in ascending order and returns an array the same size as A.
Syntax: sort(A)
>> sum(A)
ans =
8 14 18
MULTIDIMENSIONAL ARRAYS