MATLAB: How to compute the mean, standard deviation, minimum, and maximum of a vector without using MATLAB’s std function

I need to write a function that computes the mean, standard deviation, minimum & maximum values and range of a ten element vector, without using the std function. Instead i've been given the equation (last x is meant to be x-bar but couldn't work out how to write it):
σ =((1/N)(∑_(i=1)^n)(x-x) )
N is the number of data points (10 in this case) and x-bar is the mean value of x.
I can use any other functions except std.

Best Answer

Say you have
>> x = [4, 8, 7, 5] ;
>> b = 6 ;
If you wanted to subtract b to each element of x, you would do it with:
>> y = x - b
y =
-2 2 1 -1
this is a vector operation: in one shot, you operate on all elements, without having to use a loop. Now if you look up for element-wise operations in MATLAB, you will realize that for operators which have a matrix definition, like the product *, there is an element-wise version whose syntax involves a dot, e.g. .*. Same for ^ and .^.
You might not know what a matrix product is, but the element-wise product is the usual product applied to each element. Now I let you experiment with that, e.g. if you wanted to square all elements of a vector.