• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes
How does Matlab calculate standard deviation?

How do you find the good "STD" or standard deviation of a matrix? What does it mean, i want to understand with example.
by (1.4k points)  
reshown by

1 Answer

0 votes

In this answer we're going to use the concepts that we've been developing with regard to vectors and we're going to do some very basic statistical calculations with them because a lot of times if you have raw data you'll store it in a vector which is just a list of numbers so it might be handy to be able to calculate a few key parameters so for instance may have I may be a teacher and so I may have some students and I maybe collecting grades so let's say some of the grades in the class are 190 190 285 one guy got a really bad grade of forty or one lady got a bad grade of a forty then I have one C and then most people in the class doing pretty good something like that so these are all the grades in my class of course keep in mind I think I may have you know two hundred people in my class and have a much longer vector.

So here's my grades vector it's all it's all compactly held together everything's in one nice unit that I'm calling grades and I might need to know I might like to know okay well let's go ahead and figure out what is the mean of these of these students here so they're the function for that in MATLAB is just mean and you just pass the vector grades to it and then it'll basically calculate the mean in the normal way add everything up divided by the number of items there so the mean for this this class is 84.6% a median so the function for that is median and it'll go off and look at the middle value there this is a good opportunity to to also use another function that we learned in a previous lesson if you use sorts on the vector grades then it'll order it'll order my vector from least to from smallest number to larger number so if I order them like this and I can look in them right in the middle here is a 91 and that's why the median is 91 that's the definition of what a median is you order your list of numbers from smallest to largest and the median is whatever is gonna lie in the middle.

 whereas the the mean is more of a calculated value where you add everything up and by the number there so let me clear the screen get that clutter off put our grades back up on the screen now another thing we might be interested to figure out is the standard deviation because a lot of times the mean is not that important well it's important but it's not a complete picture without knowing what the standard deviation is so if we go and want to do the standard deviation its STD stance that means standard deviation and you pass it the vector grades that you've created and then it calculates a standard deviation of 17.9 so when you look at the mean and the standard deviation together that gives you a complete picture you know if you were to plot this and fit it to it to a bell curve or a normal distribution that would give you the complete picture it's important to know that the mean of the student grades is about an eighty five eighty four point six but it's also very important to know that the standard deviation is about 17 so that means that if you kind of look at it as a bell curve then the distributions really gonna start to taper off when you get to around 17 or 18 points away from either side of the mean now again here's a good opportunity to use some of our previous our previous stuff I can take make unmake another another vector called grades 2 so what I'll do is I'll modify this guy so what I want to do is I want to start off with the grades that I originally had but I want to add some other grades to it let's say I had some transfer students come in at the last minute so I had my original grades and now I want to add in maybe like four or five other grades and let's say these other grades were really really poor so let's say they did really bad here this guy got 24 this person got you know 51 this person got 47 this person got you know 16 that's relatively good and this person just did terrible with 19 he just didn't study at all for the test so what I'm doing here is I'm creating another vector and I'm gonna have the values of the original vector that I have up here but I'm going to kind of append at the end these additional grades and so you can see that that's what I have here this vector contains the original grades and then over here I start to add these other guys here so whenever I go back and try to calculate the mean of this you would expect it shift lower so let me put the mean of grades too of course is now a 68 as compared to the 84 that it was and the standard deviation should change a lot to grades too the standard deviation is much wider because I have these outliers over here that's basically you know kind of tore up the class performance so the mean shifts lower and the bell curve so to speak gets wider these so the the the the shape of it if you if you if you fit it to a normal distribution to a bell curve so to speak gets fatter because you know the average distance so to speak away from the mean is whopping 28 points now and if you had a class of overachievers you know with really high grades grades 3 if you had a class of very high achievers then you might have a hundred hundred hundred one guy got a nice seven when a guy got a 95 one guy got a 90 we gotten out of 96 and if you calculate the mean of these guys of course the mean is gonna be very high and the standard deviation it's gonna be really tight you see how the standard deviation is only three point six it's because these grades are so tightly compacted so the mean is 96 and this standard deviation tells you that the spread of the students is not that great it means they're all doing really well and finally I'll close out by saying the standard deviation is super important in statistics sometimes you might want to calculate the variance so let's calculate the variance of grades 3 and you do that with a var command and the variance is 13 and for those of you have taken statistics you'll know that the variance is simply the standard deviation squared so if you actually take take this 3.67 I'll just do it three point six seven one zero and square you're gonna get the variance there so MATLAB has built-in commands for mean standard deviation variance and medians so definitely use those guys a lot of times you'll import data you want to do quick analysis on it those are the basics those are the things that are gonna get you by with most of what you're gonna do in everyday situations and of course when you get into more advanced statistics MATLAB has a whole additional suite of other tool you can use to tackle your problems  

by (9.8k points)