Center and scale data in the Live Editor
The Normalize Data task lets you interactively normalize data by choosing centering and scaling methods, such as z-score. The task automatically generates MATLAB® code for your live script.
Using this task, you can:
Customize how to center and scale data in a workspace variable such as a table or timetable.
Visualize the input data compared to the normalized data.
Output the centering and scaling values used to compute the normalization.
Open the Task
To add the Normalize Data task to a live script in the MATLAB Live Editor:
On the Live Editor tab, click Task and select the Normalize Data icon .
In a code block in the live script, type a relevant keyword, such as
Normalize Datafrom the suggested command completions.
Input data — Valid input data from workspace
vector | table | timetable
This task operates on input data contained in a vector, table, or timetable. The
data can be of type
For table or timetable input data, to clean all variables with type
supported variables. To choose which
double variables to clean, select
Normalization method — Method and parameters for normalizing data
Z-score (default) |
Range | ...
Specify the method and related parameters for normalizing data as one of these options.
Center and scale to have mean
Center and scale to have median
Positive numeric scalar (default is
|Scale data by p-norm.|
Upper and lower range limits (default is
|Rescale range of data to an interval of the form |
Center and scale data to have median
|Center to have mean |
|Center to have median |
|Shift center by a specified numeric value.|
|Shift center using values in a numeric array or in a table whose variable names match the specified table variables from the input data.|
Scale data by standard deviation.
|Scale data by median absolute deviation.|
|Scale data by first element of data.|
|Scale data by interquartile range.|
Numeric scalar (default is 1)
|Scale data by dividing by a specified numeric value.|
|Scale data using values in a numeric array or in a table whose variable names match the specified table variables from the input data.|
|See the ||Both center and scale data using the specified parameters.|
For a random variable X with mean μ and standard deviation σ, the z-score of a value x is For sample data with mean and standard deviation S, the z-score of a data point x is
z-scores measure the distance of a data point from the mean in terms of the standard deviation. The standardized data set has mean 0 and standard deviation 1, and it retains the shape properties of the original data set (same skewness and kurtosis).
Median Absolute Deviation
The median absolute deviation (MAD) of a data set is the median value of the absolute deviations from the median of the data: . Therefore, the MAD describes the variability of the data in relation to the median.
The MAD is generally preferred over using the standard deviation of the data when the data contains outliers. The standard deviation squares deviations from the mean, giving outliers an unduly large impact. Conversely, the deviations of a small number of outliers do not affect the MAD.
The general definition for the p-norm of a vector v that has N elements is
where p is any positive real value or
Inf. For common values of p:
If p is 1, then the resulting 1-norm is the sum of the absolute values of the vector elements.
If p is 2, then the resulting 2-norm is the vector magnitude or Euclidean length of the vector.
If p is
Inf, then .
Rescaling changes the distance between the minimum and maximum values in a data set by stretching or squeezing the points along the number line. The z-scores of the data are preserved, so the shape of the distribution remains the same.
The equation for rescaling data X to an arbitrary interval [a, b] is
The interquartile range (IQR) of a data set describes the range of the middle 50% of values when the values are sorted. If the median of the data is Q2, the median of the lower half of the data is Q1, and the median of the upper half of the data is Q3, then .
The IQR is generally preferred over looking at the full range of the data when the data contains outliers because the IQR excludes the largest 25% and smallest 25% of values in the data.
Version HistoryIntroduced in R2021b
R2022b: Plot multiple table variables
Simultaneously plot multiple table variables in the display of this Live Editor task. For table or timetable data, to visualize all selected table variables at once in a tiled chart layout, set the Variable to display field.
R2022b: Append normalized variables
Append input table variables with table variables containing normalized data. For table or timetable input data, to append the normalized data, set the Output format field.
R2022a: Live Editor task does not run automatically if inputs have more than 1 million elements
This Live Editor task does not run automatically if the inputs have more than 1 million elements. In previous releases, the task always ran automatically for inputs of any size. If the inputs have a large number of elements, then the code generated by this task can take a noticeable amount of time to run (more than a few seconds).
When a task does not run automatically, the Autorun icon is disabled.
To run a task manually, on the Live Editor tab, click the Run Section button.
To enable running the section automatically, click the Autorun icon. The icon updates to display the enabled state.