The mean, standard deviation and coefficient of variation can be computed using for loops in MATLAB by first calculating the sum of the elements and the total number of elements in the array. Here is an example:
main.m656 chars29 lines
In this example, we loop through each element of the array to calculate the sum of the elements and the squared difference of each element from the mean. We then calculate the mean, standard deviation and coefficient of variation using the formulas:
mean_x = sum_x / n
std_dev_x = sqrt(sum((x - mean_x)^2) / (n-1))
cv_x = std_dev_x / mean_x * 100
Note that the denominator for the standard deviation calculation is (n-1) instead of n to correct for the bias due to using the same data to estimate both the mean and the deviations.
gistlibby LogSnag