Shruti01
Member level 3
- Joined
- Apr 14, 2010
- Messages
- 67
- Helped
- 3
- Reputation
- 6
- Reaction score
- 3
- Trophy points
- 1,288
- Location
- Mumbai, India
- Activity points
- 1,941
Hello all,
I have written following matlab code for calculating the mean and standard deviation of x but I am getting an error for mean and standard deviation as NaN (Not a number). Kindly help. What is wrong with my code.
I have written following matlab code for calculating the mean and standard deviation of x but I am getting an error for mean and standard deviation as NaN (Not a number). Kindly help. What is wrong with my code.
Code:
clc;
close all;
clear all;
x = [4.2426 + 3.1659i
2.2956 + 2.3891i
-2.2271 + 4.5607i
-1.9326 - 3.1940i
3.6840 + 3.0343i
0.0677 + 2.9262i
-2.9779 - 1.4531i
-2.4633 + 3.2697i
-3.9887 + 0.4685i
-2.9322 - 2.2252i
-4.3754 - 2.6187i
-3.4865 - 3.4461i];
sum_x = 0;
sum_x2 = 0;
n=0;
while x>=0
n=n+1;
sum_x=sum_x+x;
sum_x2=sum_x2+x^2;
end
x_bar=sum_x/n;
std_dev=sqrt((n*sum_x2-sum_x^2)/(n*(n-1)));