简体   繁体   中英

How to calculate the number of data points within a dataset that are x standard deviations from the mean in Matlab

Hello I am new to programming in Matlab and am attempting to find the number of data points within a set of data that are x standard deviations away from the mean. The dataset is 5,000 random numbers using randn. I would like to do this with a loop, and I think the steps are should take are as follows:

  1. Have a loop go through the 5,000 random data points
  2. Count the points that are +- 1 std from the mean
  3. Print the number of points

I am not really sure where to begin and if someone could point me in the right direction it would be greatly appreciated. Thanks.

N = 5000;         % Number of data points
x = randn(N,1);   % Random vector
mu = mean(x);     % Mean of vector
sig = std(x);     % Stan. dev. of vector

% This is a logical array that signifies where the
% condition is true.
inds = (x >= (mu - sig)) & (x <= (mu + sig));

Can you take it from here?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM