Mean: mean
Standard Deviation: std Answer from Star Strider on mathworks.com
MathWorks
mathworks.com › matlab › data import and analysis › descriptive statistics and insights
std - Standard deviation - MATLAB
This MATLAB function returns the standard deviation of the elements of A along the first array dimension whose size does not equal 1.
MathWorks
mathworks.com › matlab › data import and analysis › descriptive statistics and insights
movstd - Moving standard deviation - MATLAB
S = movstd(A,k) returns the local k-point standard deviation values. Each standard deviation is calculated over a sliding window of length k across neighboring elements in A. When k is odd, the window is centered about the element in the current position. When k is even, the window is centered ...
03:41
MATLAB Tutorial: How to Calculate Mean, Median, Standard Deviation, ...
04:21
MATLAB Random #s, Mean, Standard Deviation - YouTube
01:49
Standard Deviation in MATLAB without using std - YouTube
11:14
MATLAB Statistics Tutorial: Mean, Median, Mode & Standard Deviation ...
MATLAB Statistics Basics — Mean, Median and Standard ...
MathWorks
mathworks.com › image processing toolbox › image segmentation and analysis › region and image properties
std2 - Standard deviation of matrix elements - MATLAB
This MATLAB function computes the standard deviation of all values in array A.
MathWorks
mathworks.com › statistics and machine learning toolbox › descriptive statistics and visualization › descriptive statistics
nanstd - (Not recommended) Standard deviation, ignoring NaN values - MATLAB
This MATLAB function is the standard deviation std of X, computed after removing all NaN values.
MathWorks
mathworks.com › matlab › language fundamentals › data types › time series
std - Standard deviation of timeseries data - MATLAB
This MATLAB function returns the standard deviation of the data in a timeseries object.
YouTube
youtube.com › math and science
Matlab Tutorial - 33 - Calculating Mean, Median, and Standard Deviation of Data in a Vector - YouTube
Get more lessons like this at http://www.MathTutorDVD.com Learn how to calculate the standard deviation of the elements of data in a vector in matlab. We als...
Published: March 23, 2018
Views: 10K
MathWorks
mathworks.com › statistics and machine learning toolbox › probability distributions and hypothesis tests › univariate continuous distributions
std - Standard deviation of probability distribution - MATLAB
This MATLAB function returns the standard deviation s of the probability distribution pd.
MathWorks
mathworks.com › matlabcentral › answers › 319464-simple-question-about-standard-deviation
Simple question about Standard Deviation. - MATLAB Answers - MATLAB Central
January 8, 2017 - By default, it will give the sample standard deviation. Call it as ... to get the population. That is explained in the documentation for std, in the section describing the input argument weight. ... https://www.mathworks.com/matlabcentral/answers/319464-simple-question-about-standard-deviation#comment_418675
Johns Hopkins University
math.jhu.edu › ~shiffman › 370 › help › techdoc › ref › std.html
std (MATLAB Function Reference)
s = std(X,flag,dim) computes the standard deviations along the dimension of X specified by scalar dim.
Top answer 1 of 2
2
You are getting a different answer because you are not even doing what you said you wanted to do. Should you be surprised? Your code does some nasty stuff inside that loop that does not do what you apparently think you wanted to do.
By the way, a REALLY bad idea is to use the letter o for a variable name. One day you will end up with bugs in your code because you typed the number 0 instead of o someplace.
Anyway, there are two possible standard deviations to consider. A population standard deviation, or a sample standard deviation. The difference depends on whether you divide by n or n-1. What you described, taking a mean, implies a population standard deviation. But then you divided by o-1.
std(a(:))
does what you want, unless you really did want a population standard deviation. In that case, use
std(a(:),1)
Do you really feel the need to verify that MATLAB knows how to compute a standard deviation, so that you need to do it by hand to check?
std(a(:))
ans =
2.64344051905425
sqrt(sum((a(:) - mean(a(:))).^2)/(numel(a)-1))
ans =
2.64344051905425
Yes. You could do it using loops. But if you intend to learn MATLAB, then learn to use it as it should be used.
2 of 2
0
you can use std function
std(a(:))
If you want to use your for loop, you have to correct some errors
a=[3 -2 1;4 0 5;1 2.2 -3]
m=numel(a)
som=0;
for i=1:m;
som=som+a(i);
end
avg=som/m;
o=numel(a)
sd=0;
for i=1:o;
sd=sd+(a(i)-avg)^2;
end
sd=(sd/(o-1))^(1/2)
Top answer 1 of 3
1
A = [1 2 3;4 5 6;7 8 9]
A =
1 2 3
4 5 6
7 8 9
>> std(A)
ans =
3 3 3
It works just fine.
std([1 4 7])
ans =
3
sqrt(6)
ans =
2.4495
I think what you misunderstand is there are indeed two ways to compute the standard deviation of a set of numbers. (This gets into basic probability and statistics. Hey, you are using the standard deviation. A stats class might be useful.)
The difference is that betyween the standard deviation of a complete population, and the standard deviation of a random sample form a distribution. The two get different formulas, for a good reason. If you want to compute the standard deviation of the complete population, then used std, with the second argument as 1.
std([1 4 7],1)
ans =
2.4495
When does the difference matter? The difference is seen when we try to compute the standard deviation of a complete population.
So if we have just the 6 numbers on the 6 faces of a fair die, the standard deviation of the population is
x = 1:6;
>> sqrt(sum((x - mean(x)).^2)/6)
ans =
1.7078
>> std(1:6,1)
ans =
1.7078
As you can see, std does that, if we use 1 as the second argument. That causes std to use the formula that apparently you know, dividing by n inside the sqrt.
However, when you compute the standard deviation of a random sample of numbers, if you divide by n, thus the number of data points, this will give you a biased estimator. (Again, basic prob and stats.)
X = randn(10,1e7);
>> mean(std(X,1))
ans =
0.92264
>> mean(std(X))
ans =
0.97255
So above, I generated 1e7 sets of 10 numbers, sampled from a Gaussian with a unit standard deviation. If we use the formula where we divide by n (thus std(X,1)) we get a biased estimate. It tends to be a little low. However, the usual formula for a statistical sample, where the mean itself is ALSO an estimate, yields a better estimate of the standard deviation. Again, basic prob & stats.
But this is why there are TWO formulas for the standard deviation, and why you need to know which one to use and when.
2 of 3
1
It is not wrong. The difference is explained in detail here:
https://en.wikipedia.org/wiki/Standard_deviation#Corrected_sample_standard_deviation
You can easily get the answer you want by following the advice given in the std documentation, which states "Some definitions of standard deviation use a normalization factor of N instead of N-1, which you can specify by setting w to 1." e.g.:
>> std(M,1)
ans =
2.4495 2.4495 2.4495
>> sqrt(6)
ans =
2.4495
MathWorks
mathworks.com › matlabcentral › answers › 516834-data-manipulation-increase-standard-deviation
data manipulation: increase standard deviation - MATLAB Answers - MATLAB Central
April 10, 2020 - Standard Deviation gives an estimate of the size of a typical deviation from the mean.
MathWorks
mathworks.com › matlabcentral › answers › 603577-need-help-manually-finding-the-standard-deviation-using-an-external-function
Need help manually finding the standard deviation using an external function - MATLAB Answers - MATLAB Central
October 2, 2020 - In your formula, there is a division by N. This is an unbiased estimator of standard deviation. Your formula is a biased estimator. Both are equally valid, and you should use the one given to you. Read the discussion here: https://en.wikipedia.org/wiki/Standard_deviation#Estimation. You cannot make the MATLAB's std result match your formula.