Filter löschen
Filter löschen

Descriptive Statistics of entire array

4 Ansichten (letzte 30 Tage)
Matthew Piccolo
Matthew Piccolo am 13 Apr. 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.

Antworten (2)

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

Melden Sie sich an, um zu kommentieren.


Andrii Mishchenko
Andrii Mishchenko am 12 Aug. 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!

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by