
- MATLAB - Home
- MATLAB - Overview
- MATLAB - Features
- MATLAB - Environment Setup
- MATLAB - Editors
- MATLAB - Online
- MATLAB - Workspace
- MATLAB - Syntax
- MATLAB - Variables
- MATLAB - Commands
- MATLAB - Data Types
- MATLAB - Operators
- MATLAB - Dates and Time
- MATLAB - Numbers
- MATLAB - Random Numbers
- MATLAB - Strings and Characters
- MATLAB - Text Formatting
- MATLAB - Timetables
- MATLAB - M-Files
- MATLAB - Colon Notation
- MATLAB - Data Import
- MATLAB - Data Output
- MATLAB - Normalize Data
- MATLAB - Predefined Variables
- MATLAB - Decision Making
- MATLAB - Decisions
- MATLAB - If End Statement
- MATLAB - If Else Statement
- MATLAB - If…Elseif Else Statement
- MATLAB - Nest If Statememt
- MATLAB - Switch Statement
- MATLAB - Nested Switch
- MATLAB - Loops
- MATLAB - Loops
- MATLAB - For Loop
- MATLAB - While Loop
- MATLAB - Nested Loops
- MATLAB - Break Statement
- MATLAB - Continue Statement
- MATLAB - End Statement
- MATLAB - Arrays
- MATLAB - Arrays
- MATLAB - Vectors
- MATLAB - Transpose Operator
- MATLAB - Array Indexing
- MATLAB - Multi-Dimensional Array
- MATLAB - Compatible Arrays
- MATLAB - Categorical Arrays
- MATLAB - Cell Arrays
- MATLAB - Matrix
- MATLAB - Sparse Matrix
- MATLAB - Tables
- MATLAB - Structures
- MATLAB - Array Multiplication
- MATLAB - Array Division
- MATLAB - Array Functions
- MATLAB - Functions
- MATLAB - Functions
- MATLAB - Function Arguments
- MATLAB - Anonymous Functions
- MATLAB - Nested Functions
- MATLAB - Return Statement
- MATLAB - Void Function
- MATLAB - Local Functions
- MATLAB - Global Variables
- MATLAB - Function Handles
- MATLAB - Filter Function
- MATLAB - Factorial
- MATLAB - Private Functions
- MATLAB - Sub-functions
- MATLAB - Recursive Functions
- MATLAB - Function Precedence Order
- MATLAB - Map Function
- MATLAB - Mean Function
- MATLAB - End Function
- MATLAB - Error Handling
- MATLAB - Error Handling
- MATLAB - Try...Catch statement
- MATLAB - Debugging
- MATLAB - Plotting
- MATLAB - Plotting
- MATLAB - Plot Arrays
- MATLAB - Plot Vectors
- MATLAB - Bar Graph
- MATLAB - Histograms
- MATLAB - Graphics
- MATLAB - 2D Line Plot
- MATLAB - 3D Plots
- MATLAB - Formatting a Plot
- MATLAB - Logarithmic Axes Plots
- MATLAB - Plotting Error Bars
- MATLAB - Plot a 3D Contour
- MATLAB - Polar Plots
- MATLAB - Scatter Plots
- MATLAB - Plot Expression or Function
- MATLAB - Draw Rectangle
- MATLAB - Plot Spectrogram
- MATLAB - Plot Mesh Surface
- MATLAB - Plot Sine Wave
- MATLAB - Interpolation
- MATLAB - Interpolation
- MATLAB - Linear Interpolation
- MATLAB - 2D Array Interpolation
- MATLAB - 3D Array Interpolation
- MATLAB - Polynomials
- MATLAB - Polynomials
- MATLAB - Polynomial Addition
- MATLAB - Polynomial Multiplication
- MATLAB - Polynomial Division
- MATLAB - Derivatives of Polynomials
- MATLAB - Transformation
- MATLAB - Transforms
- MATLAB - Laplace Transform
- MATLAB - Laplacian Filter
- MATLAB - Laplacian of Gaussian Filter
- MATLAB - Inverse Fourier transform
- MATLAB - Fourier Transform
- MATLAB - Fast Fourier Transform
- MATLAB - 2-D Inverse Cosine Transform
- MATLAB - Add Legend to Axes
- MATLAB - Object Oriented
- MATLAB - Object Oriented Programming
- MATLAB - Classes and Object
- MATLAB - Functions Overloading
- MATLAB - Operator Overloading
- MATLAB - User-Defined Classes
- MATLAB - Copy Objects
- MATLAB - Algebra
- MATLAB - Linear Algebra
- MATLAB - Gauss Elimination
- MATLAB - Gauss-Jordan Elimination
- MATLAB - Reduced Row Echelon Form
- MATLAB - Eigenvalues and Eigenvectors
- MATLAB - Integration
- MATLAB - Integration
- MATLAB - Double Integral
- MATLAB - Trapezoidal Rule
- MATLAB - Simpson's Rule
- MATLAB - Miscellenous
- MATLAB - Calculus
- MATLAB - Differential
- MATLAB - Inverse of Matrix
- MATLAB - GNU Octave
- MATLAB - Simulink
MATLAB - Normalize Data
Matlab is a powerful language which allows you to do a lot of stuff with problem solving, analysis of data, a lot with matrices, vectors , scientific computing etc.
There is a rich source of libraries and other softwares that are used in matlab that makes your life easy. Here we are going to discuss Normalisation of data in Matlab.
The term normalisation deals with organising the data. We are just going to learn the same as how to normalise i.e organise data in matlab.
Normalization is the most common step in data analysis that scales the values of a dataset to a specific range, often between 0 and 1.In Matlab the normalization on dataset can be done using normalize function.The function normalize comes with various options that includes range and type of normalization that can be performed on it.
Syntax
N = normalize(X) N = normalize(X,dim) N = normalize(___,method) N = normalize(___,method,methodtype)
Let us understand each of the syntax with description and examples.
N = normalize(X)
The function will return the z-score data from X, with center as 0 and standard deviation is 1.
Z-score measures the number of standard deviations from above and below the mean value.
The formula for z-score is −
$$\mathrm{Z=\frac{(x\: -\:\mu )}{\sigma }}$$
Here x = observed value or data point.
$\mathrm{\mu}$ is the mean point
$\mathrm{\sigma}$ is the standard deviation.
For the normalize method the input X can be a vector, matrix, multidimensional array or a table.
Following are the ways in which normalize function will operate based on the input given.
- If the given input X is vector , the nomalize function will operate on all the vector in X.
- If the given input X is matrix then the normalize function will act on each column in X separately.
- If the given input X is a multidimensional array, then normalize function will first operate on the first dimension of X whose size is not equal to 1.
- If the input given to X is a table or timetable the normalize function will operate on each variable of X separately.
Let us see a few examples with the function normalize(X).
Example 1
In the example below we are going to use X as vector
X = 1:10; N = normalize(X)
On execution in Matlab the output is as follows −
>> X = 1:10; N = normalize(X) N = -1.4863 -1.1560 -0.8257 -0.4954 -0.1651 0.1651 0.4954 0.8257 1.1560 1.4863 >>
Example 2
In the example below we are going to use X as a matrix.
X = magic(3) N = normalize(X)
On execution in Matlab the output is as follows −
>> X = magic(3) N = normalize(X) X = 8 1 6 3 5 7 4 9 2 N = 1.1339 -1.0000 0.3780 -0.7559 0 0.7559 -0.3780 1.0000 -1.1339
N = normalize(X,dim)
In above syntax dim is the dimension of matrix X. So as the dimension given the normalize function will operate on that dimension. For example if the dimension given is 2. The normalize function will operate on each row.
Example
X = magic(3) N = normalize(X, 2)
On execution in Matlab the output is as follows −
>> X = magic(3) N = normalize(X, 2) X = 8 1 6 3 5 7 4 9 2 N = 0.8321 -1.1094 0.2774 -1.0000 0 1.0000 -0.2774 1.1094 -0.8321 >>
N = normalize(___,method)
In this syntax the normalization will operate as the method given. The method used can be center, scale , norm, range and zscore.
Example
In this example will use the vector as X and the method scale.
X = 1:5; N = normalize(X,"scale")
On execution in matlab the output is
>> X = 1:5; N = normalize(X,"scale") N = 0.6325 1.2649 1.8974 2.5298 3.1623
Let us try the same example using range method
>> X = 1:5; N = normalize(X,"range") N = 0 0.2500 0.5000 0.7500 1.0000 >>
N = normalize(___,method,methodtype)
Here the normalize function will act based on the method and methodtype given.
Following are the combination for method and methodtype.
Method | Method Type | Description |
---|---|---|
zscore | std (default) | Get the z-score value.The center data to have mean value as 0 and scale data to have standard deviation as 1. |
robust | Calculate the z-score value with center data having mean as 0, and scale data having median absolute deviation as 1. | |
norm | Positive numeric scalar (default is 2) | For normalization factor p-norm is used where p is a positive integer. |
Inf | For normalization factor p-norm is used where p is infinity. | |
scale | std (default) | Scaling data to have standard deviation as 1. |
mad | Median absolute deviation as 1 while scaling the data. | |
first | The first element of the data is used for scaling. | |
iqr | Interquatile range is used for scaling data | |
Numeric array | Numeric array is used for scaling data. | |
Table | Table variables are used to scale data. | |
range | 2-element row vector (default is [0 1]) | Rescale range of data to [a b], where a < b. |
center | "mean" (default) | Center data to have mean 0. |
"median" | Center data to have mean 0. | |
Numeric array | Numeric array is used for center data. | |
Table | Table variables are used for center data. |
Example 1
In this example will make use of norm method and positive interger value as method type.
X = 1:5; N = normalize(X,"norm",2)
When you execute above code in matlab command window the output is as follows −
>> X = 1:5; N = normalize(X,"norm",2) N = 0.1348 0.2697 0.4045 0.5394 0.6742 >>
Example 2
In this example will make use of center as the method and mean as the method type.
X = 1:5; N = normalize(X,"center","mean")
On execution in matlab command window the output is as follows −
>> X = 1:5; N = normalize(X,"center","mean") N = -2 -1 0 1 2 >>