calculate mean of matrix in matlab

To calculate the mean of a matrix in Matlab, you can use the mean function. The mean function calculates the mean of the elements of a matrix along a specified dimension.

Here is an example code:

main.m
% Create a matrix
A = [1 2 3; 4 5 6; 7 8 9];

% Calculate the mean of the matrix along the rows (dimension 1)
mean_A_rows = mean(A, 1);

% Calculate the mean of the matrix along the columns (dimension 2)
mean_A_columns = mean(A, 2);
233 chars
9 lines

In this example, mean_A_rows is a vector containing the means of each row of the matrix A. Similarly, mean_A_columns is a vector containing the means of each column of the matrix A.

gistlibby LogSnag