fix - Round toward zero - MATLAB (original) (raw)
Main Content
Syntax
Description
Y = fix([X](#bul3slv-X))
rounds each element ofX
to the nearest integer toward zero. This operation effectively truncates the numbers in X
to integers by removing the decimal portion of each number:
- For positive numbers, the behavior of
fix
is the same asfloor
. - For negative numbers, the behavior of
fix
is the same asceil
.
Examples
Round Matrix Elements Toward Zero
X = [-1.9 -3.4; 1.6 2.5; -4.5 4.5]
X = 3×2
-1.9000 -3.4000 1.6000 2.5000 -4.5000 4.5000
Round Complex Numbers Toward Zero
X = [1.4+2.3i 3.1-2.2i -5.3+10.9i]
X = 1×3 complex
1.4000 + 2.3000i 3.1000 - 2.2000i -5.3000 +10.9000i
Y = 1×3 complex
1.0000 + 2.0000i 3.0000 - 2.0000i -5.0000 +10.0000i
Input Arguments
X
— Input array
scalar | vector | matrix | multidimensional array | table | timetable
Input array, specified as a scalar, vector, matrix, multidimensional array, table, or timetable. For complex X
, fix
treats the real and imaginary parts independently.
fix
converts logical and char
elements of X
into double
values.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| char
| logical
| table
| timetable
Complex Number Support: Yes
Extended Capabilities
Tall Arrays
Calculate with arrays that have more rows than fit in memory.
Thefix
function fully supports tall arrays. For more information, see Tall Arrays.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
The fix
function fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced before R2006a
R2023a: Perform calculations directly on tables and timetables
The fix
function can calculate on all variables within a table or timetable without indexing to access those variables. All variables must have data types that support the calculation. For more information, see Direct Calculations on Tables and Timetables.