0

I am supposed to combine all the matrix into one, which concatenate horizontally by

matrix = [matrix1 matrix2 matrix3];

now i have to find the mean of the matrix which is 32 x 2039 dimensions.

i tried looping through each row and using mean for the whole elements in that row multipled and divided by the number of elements which is 2039.

answer i get is -Inf, all the time.

help would be appreciated. thanks

my code what i could remember in case

[r, c] = size(matrix);
for i = 1:r
   rowvalues = matrix(i,[1:c]);
   mean(i,1) = mean2(rowvalues); %or mean(rowvalues,2);
end

results in -Inf.

my aim is to calculate the mean of the matrix which should be 39 X 1 dimensions. thanks

Seif Sharif
  • 103
  • 1
  • 2
  • 10

1 Answers1

0

When an element of a row is -Inf, the whole row will have a mean=-Inf. I suggest you check this with the following code:

% The indices of the occurences of -Inf in matrix
mInfIndices=(matrix==-Inf);
% Does the row contain an -Inf?
mInfInRows=sum(mInfIndices,2)>0;
disp(mInfInRows);

This way you will see which rows contain a -Inf.

CyDe
  • 23
  • 5
  • it was my mistake, i did a dumb mistake i tried calculating the mean by multiplying all element of first row and dividing it by the number of elements instead of sum. – Seif Sharif Mar 19 '13 at 16:52