In a set of data that I am trying to find the mean and std of, how can I input multiple copies of the same number?

3 views (last 30 days)
Hello, I have a project in which I am studying a set of data consisting of about 4000+ numbers. I must find the mean and standard deviation of these numbers. All of the numbers in the set have multiple copies of each other, such as 1.74336 showing up in the data set 500+ times. Is there a code that can basically duplicate numbers in a data set a certain amount of times? I have the student edition of matlab 2014 so I would need a code that doesn't need any of the non-included toolboxes. Thank you so much for any help! I have included a sample of the data set as an attachment where the left side is the data and the right column is the number of occurrences.

Answers (2)

Walter Roberson
Walter Roberson on 7 Feb 2016
repmat(1.74336, 5, 8)
would create a 5 x 8 array containing 1.74336
Another way of doing this is
1.74336 * ones(5,8)
repmat() is useful for duplicating entire rows or columns.

Star Strider
Star Strider on 7 Feb 2016
Those are the weighted mean and standard deviation. The MATLAB std function supports weighs, so I refer you to the documentation for that. The mean function does not, but it’s straightforward to calcualate it:
M = [1171 11
1171.05 6
1171.1 16
1171.15 11
1171.2 8
1171.25 10
1171.3 14
1171.35 11
1171.4 9
1171.45 11
1171.5 13
1171.55 12
1171.6 11
1171.65 10];
wmean = sum(M(:,1).*M(:,2))/sum(M(:,2)); % Weighted Mean
wstd = std(M(:,1), M(:,2),1); % Weighted Standard Deviation
I just used a few rows of your matrix, but this will work for your entire population.

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!