Borrar filtros
Borrar filtros

Descriptive Statistics of entire array

4 visualizaciones (últimos 30 días)
Matthew Piccolo
Matthew Piccolo el 13 de Abr. de 2017
Respondida: Andrii Mishchenko el 12 de Ag. de 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.

Respuestas (2)

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

Iniciar sesión para comentar.


Andrii Mishchenko
Andrii Mishchenko el 12 de Ag. de 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!

Categorías

Más información sobre Tables en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by