필터 지우기
필터 지우기

Descriptive Statistics of entire array

조회 수: 6 (최근 30일)
Matthew Piccolo
Matthew Piccolo 2017년 4월 13일
답변: Andrii Mishchenko 2017년 8월 12일
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.

답변 (2개)

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

댓글을 달려면 로그인하십시오.


Andrii Mishchenko
Andrii Mishchenko 2017년 8월 12일
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!

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by