How to Calculate Variance in MATLAB? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Pre-requisites: Calculate Variance In statistical mathematics, Variance is the measure of dispersion of a given data from its average value. This is a very important quantity in statistics and many other fields like Machine Learning and AI. Variance in MATLAB:MATLAB provides a simple function to calculate the variance of a given data, the var() function. Syntax: variance = var(<data>, <weight>, ...) Here, the <data> is a vector or array of data, and <weight> is an optional argument used for weighted data. Let's see the usage of var with some examples. Example 1: Matlab % MATLAB code for Calculating the % variance of a 1D vector [23:75]. % Creating a vector data = 23:75; % Calculating variance variance = var(data); disp(variance) Output: The calculated variance is 238.50, which can be verified manually. Calculating variance of weighted data. We use the same vector but, just add another vector which stores the weight of every element in the data. Example 2: Matlab % MATLAB code for creating a vector and weights data = 23:75; w=linspace(3,13,53); %calculating variance variance = var(data,w); disp(variance) Output: This will give, us the weighted variance of the user data and weights. We can also calculate the variance of a multidimensional vector along a particular dimension (less than the maximum dimension) as follows. Example 3: Matlab % MATLAB code forcreating a vector and weights data = [1 3 -2; 2 3 7; 0 4 2.1]; % w = [0.1, 3, 2.1]; % Calculating variance at all dimensions var(data,0,"all") % Calculating variance at 1st dimension var(data,0,1) % Calculating variance at 2nd dimension var(data,0,2) Output: Conclusion:This article discussed various ways of calculating variance in MATLAB for different kinds of data. Comment More infoAdvertise with us Next Article How to Calculate Variance in MATLAB? O owl0223 Follow Improve Article Tags : Software Engineering MATLAB-Maths Similar Reads How to Calculate Pooled Variance in R In this article, we will discuss what is Pooled Variance in R and How to Calculate Pooled Variance in the R Programming Language.What is Pooled Variance?Pooled variance refers to the combined or weighted average of variances from two or more groups. It is used in comparing means from different group 2 min read How To Calculate Variance in Excel If you're looking to understand your data better, knowing how to calculate variance in Excel is a great skill to have. Calculating Variance in Excel is a Fundamental calculation that helps to measure the dispersion or spread of data points in a dataset. Luckily, Excel makes it easy to do this with s 7 min read How to Calculate Covariance in MATLAB Covariance is the measure of the strength of correlation between two or more random variables. Covariance of two random variables X and Y can be defined as:{\displaystyle \operatorname {cov} (X,Y)={\frac {1}{n}}\sum _{i=1}^{n}(x_{i}-E(X))(y_{i}-E(Y))}Where E(X) and E(Y) are expectation or mean of ra 3 min read How to Calculate Harmonic Mean in MATLAB? Harmonic mean is a type of mean, which is a measure of central tendencies of data, in statistics that gives large weightage to smaller data and small weightage to larger data. The Harmonic Mean in mathematical terms is nothing but the reciprocal of the mean of reciprocal values of all the data eleme 2 min read How To Calculate Standard Deviation in MATLAB? Standard deviation is a statistical quantity that tells us how much-distributed data is from its mean value. Standard deviation can also be defined as the square root of the Variance of the same data. Standard Deviation in MATLAB:MATLAB provides a simple function to calculate the standard deviation 2 min read How to Calculate Expected Value in R? In this article, we are going to see how to calculate the excepted value using R Programming Language. A probability distribution describes all the possible values of random variables in the given range.Expected value of a probability distribution:μ = Σx * P(x)Where X is a Sample value and P(x) is a 2 min read How to Calculate the Coefficient of Variation in R The Coefficient of Variation (CV) is a standardized measure of dispersion in a dataset. It is defined as the ratio of the standard deviation to the mean, and it is usually expressed as a percentage. The CV is particularly valuable in statistics because it allows for the comparison of variability bet 4 min read How to create a function in MATLAB ? A function is a block of statements that intend to perform a specific task. Functions allow the users to reuse the code frequently. MATLAB has several predefined functions which are ready to use such as sin(), fact(), cos() etc. MATLAB also allows the users to define their own functions. Syntax: fun 2 min read How to Calculate the Coefficient of Variation in Excel? Coefficient of Variation is a statistical term that is used to measure the dispersion of data points with the arithmetic mean of all the data points in the series. In mathematical terms, it is the ratio of standard deviation with the mean. The formula for the coefficient of variation can be expresse 3 min read How to calculate Coefficient of Variation? Answer: Coefficient of Variation is calculated as- (Standard Deviation / Mean) à 100How to calculate the Coefficient of Variation? Statistics is the process by which the data is collected and analyzed. The coefficient of variation in statistics is explained as the ratio of the standard deviation to 6 min read Like