Descriptive Statistics of entire array

20 vues (au cours des 30 derniers jours)
Matthew Piccolo
Matthew Piccolo le 13 Avr 2017
I am working on a project where I need to create a script that at one point returns the mean, median, mode, variance, standard deviation, minimum, maximum, and count of a user inputted array. The inputted array will either be a single column of an undetermined amount of numbers, or two columns of an undetermined amount of numbers.
To use the mean function as an example, if I have a matrix
x = [1,4;5,8;3,1;7,2;4,2];
then the mean function returns a mean of each column:
mean(x) = [4,3.4];
I need a mean of ALL the elements of the matrix. So a quick fix of this would be the mean2 function:
mean2(x) = 3.7;
This is great and returns exactly what I need, except I also need to find the median, mode, variance, etc. As far as I can tell, I can't just add the number 2 to the end of the functions that produce these statistical quantities to get the same result. So I need a way to either convert the user inputted matrix into a single column matrix (without losing the original matrix) and using the statistical analysis functions that way, or just a simple way to find these analyses of every single element of the array, not just the columns at single times.

Réponses (2)

John D'Errico
John D'Errico le 13 Avr 2017
So, you can't just compute
mean(x(:))
mode(x(:))
etc?
  2 commentaires
Image Analyst
Image Analyst le 14 Avr 2017
and for the count (number of elements):
count = numel(x);
John D'Errico
John D'Errico le 14 Avr 2017
Or
prod(sixe(x))
will also work. But numel is better.

Connectez-vous pour commenter.


Andrii Mishchenko
Andrii Mishchenko le 12 Août 2017
Hello Dear, Matthew. You can use linear indexation in order to solve your problem. Let's consider your example with a matrix
x = [1,4;5,8;3,1;7,2;4,2];
If you will create a new matrix X = x(1:end) than you will obtain a row vector X containing all elements of your original matrix x. So you can perform a basic descriptive operations on this vector and calculations will be done considering all the values of the matrix x at the same time.
Cheers!

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by