Asked by John
on 21 Dec 2011

Hi there,

How would you normalize a column of data in matlab between 0 and 1 using the formula, z = (x-mean)/standard deviation. Is there a built in function to do this?

Many thanks

John

*No products are associated with this question.*

Answer by Junaid
on 21 Dec 2011

Accepted answer

Dear John,

Lets say you have matrix D and you want to normalize each value of Column to unit length (between 0-1). One possible way is :

D = bsxfun(@rdivide,D,sum(D));

each column will be unit normalized. If you take the sum of each column it will be one.

sum(D)

Do let me know if I understand you correct.

Answer by Jurgen
on 18 Nov 2012

Dividing by the maximum does not correct for offset. So only ranges 0-X go to 0-1. If his column has a negative or nonzero minimum it won't normalize to 0-1.

While the formula for correcting this is simple, mat2gray will normalize to 0-1 for you:

for i = 1:ncol D(:,i) = mat2gray(D(:,i)) end

You have to decide if you need to normalize before or after your calculation.

Opportunities for recent engineering grads.

## 0 Comments