Normalizing a matrix using matrix operations

3.6k Views Asked by At

I need some help in normalizing my matrix. I have a 5X4 matrix A. I want to normalize each column. Following is the explanation on the operations

B = Operation of matrix (A)

B matrix is 5x4 matrix. B(ij) = (A(ij)-mean of Jth column of A)/(Standard Deviation of Jth column of A)

I need to do it using matrix operations only. Mean and starndard deviations are allowed as scalar multiplications to the matrix.

1

There are 1 best solutions below

0
On

This should have been on SO.

Anyways,

for it=1:4
my_mean = mean(A(:,it));
my_sd = std(A(:,it));
B(:,it) = (A(:,it)-my_mean)/my_sd;
end

You may want to preallocate B for speed. B = zeros(5,4)