user1723765
user1723765

Reputation: 6399

Summing multiple matrices in matlab

I have a file containing 60 matrices. I would like get the mean of each value across those 60 matrices.

so the mean of the [1,1] mean of [1,2] across the matrices.

I am unable to use the mean command and am not sure what's the best way to do this.

Here's the file: https://dl.dropbox.com/u/22681355/file.mat

Upvotes: 2

Views: 2298

Answers (3)

fuyas
fuyas

Reputation: 128

You should put all the matrices together in a 3 dimensional (matrix?), mat, as:

mat(:,:,1) = mat1;
mat(:,:,2) = mat2;
mat(:,:,3) = mat3;
etc...

then simply:

mean(mat, 3);

where the parameter '3' stipulates that you want the mean accros the 3rd dimension.

Upvotes: 1

H.Muster
H.Muster

Reputation: 9317

You can try this:

 % concatenate the contents of your cell array to a 100x100x60 matrix
 c = cat(3, results_foptions{:});

 % take the mean
 thisMean = mean(c, 3);

To round to the nearest integer, you can use

 roundedMean = round(thisMean);

Upvotes: 4

slayton
slayton

Reputation: 20319

The mean of the matrix can be computed a few different ways.

First you can compute the mean of each column and then compute the mean of those means:

colMeans = mean( A );
matMean = mean(colMean);

Or you can convert the matrix to a column vector and compute the mean directly

matMean = mean( A(:) );

Upvotes: 0

Related Questions