Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

error in matlab code for mean and standard deviation

Status
Not open for further replies.

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.

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)));
 

I noticed on above code at while statement that you perform evaluation of an imaginary array number on its argument. I presume it is expected an scalar one.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top