Obtain information on a matrix

Suppose I have a matrix A and want to display information on A such as # of rows and # of columns. The average value of entries, etc. Please advise.

2 Comments

You can imagine, that the readers cannot guess what "etc." means here.

Sign in to comment.

Answers (1)

For the first, use the size function:

[rows, cols] = size(A);

For the second, create a vector from the matrix elements, then take the mean value of the vector:

Amean = mean(A(:));

Functions such as mean operate on columns, and then on vector elements, so it would otherwise be necessary to calculate ‘mean(mean(A))’. Creating a vector first is much more efficient.

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Asked:

on 22 Apr 2018

Edited:

on 22 Apr 2018

Community Treasure Hunt

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

Start Hunting!