error in matlab code for mean and standard deviation
Mostrar comentarios más antiguos
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.
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)));
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!