0
$\begingroup$

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.

  • 0
    What are you trying to do? Normalizing a vector $v$ ordinarily means just dividing the vector by its norm: $\hat{v} = v/\|v\|$. You can't just do that? What does it mean to use "matrix operations only"? And what does any of this have to do with means and standard deviations?2012-03-23
  • 0
    My matrix is a feature matrix for linear regression. Each column of the matrix A represents a feature vector. So I need to normalize each feature vector by doing (actual value - mean)/SD. I want to do in matlab. In matlab Matrix operations are easier and fast to implement than using loops.2012-03-23

1 Answers 1

1

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)