MATLAB: How to calculate mean and variance

mean

Greetings. I have generated a vector of 10,000 complex samples. I want to calculate the Mean and Variance of the samples. How can I do it without using the built-in functions _ mean()_ and * var()* ? and how do I do that in a loop? Please help.
Thank you

Best Answer

Since you want to do it without using the functions, just do:
A=rand(1000,1); %your array
sum1=0;
for i=1:length(A)
sum1=sum1+A(i);
end
M=sum1/length(A); %the mean
sum2=0;
for i=1:length(A)
sum2=sum2+ (A(i)-M)^2;
end
V=sum2/length(A); %Varaince