Tipi numerici
Le classi numeriche in MATLAB® includono numeri interi con e senza segno e numeri in virgola mobile a singola e doppia precisione. Per impostazione predefinita, MATLAB memorizza tutti i valori numerici in virgola mobile a doppia precisione. (La precisione e il tipo predefiniti non possono essere modificati). È possibile scegliere di memorizzare qualsiasi numero, o matrice di numeri, come numeri interi o a singola precisione. Gli array di numeri interi e a singola precisione offrono una memorizzazione più efficiente rispetto alla doppia precisione.
Tutti i tipi numerici supportano le operazioni di base degli array, come l'indicizzazione, il rimodellamento e le operazioni matematiche.
Funzioni
Argomenti
- Floating-Point Numbers
MATLAB represents floating-point numbers in either double-precision or single-precision format. The default is double precision.
- Single Precision Math
This example shows how to perform arithmetic and linear algebra with single precision data.
- Integers
MATLAB supports 1-, 2-, 4-, and 8-byte storage for integer data. If you use the smallest integer type that accommodates your data, you can save memory and program execution time.
- Integer Arithmetic
This example shows how to perform arithmetic on integer data representing signals and images.
- Create Complex Numbers
Create complex numbers. Complex numbers consist of a real part and an imaginary part.
- Infinity and NaN
MATLAB represents infinity by the special value
inf
, and values that are neither real nor complex by the special valueNaN
, which stands for “Not a Number”. - Identifying Numeric Classes
You can check the data type of a variable using any of these commands.
- Display Format for Numeric Values
Use the
format
function or set Preferences to control the display of numeric values. - Combining Unlike Integer Types
If you combine different integer types in a matrix (e.g., signed with unsigned, or 8-bit integers with 16-bit integers), all elements of the resulting matrix are given the data type of the leftmost element.
- Combining Integer and Noninteger Data
If you combine integers with
double
,single
, orlogical
classes, all elements of the resulting matrix are given the data type of the leftmost integer. - Empty Matrices
If you construct a matrix using empty matrix elements, the empty matrices are ignored in the resulting matrix.
- Concatenation Examples
These examples show how to concatenate different data types.
- Hexadecimal and Binary Values
Specify hexadecimal and binary values either as literals or as text. Hexadecimal and binary literals are stored as integers. You can convert text representing hexadecimal and binary values to numbers, and numbers to text representations.