Ahmad
Ahmad

Reputation: 73

How can I Normalized a matrix?

I use below code for normalizing my matrix; cause of amplitude of my data is very different in each column than other column, so my answers aren't between 0 and 1.

A = rand(m,n)
normA = max(A) - min(A);               
normA = repmat(normA, [length(a) 1]);  

normalizedA = A./normA;

a part of my original data are:

32512035.2100000    5401399.57000000    346.880000000000
32512044.0300000    5401399.54000000    346.850000000000
32512046.8900000    5401399.55000000    346.780000000000
32512049.7800000    5401399.53000000    346.860000000000
32512052.6900000    5401399.53000000    346.700000000000
32512054.0300000    5401399.53000000    346.780000000000
32512055.6900000    5401399.57000000    346.810000000000
32512063.1200000    5401399.54000000    347.800000000000
32512074.2300000    5401399.55000000    346.440000000000
32512093.1200000    5401399.54000000    346.660000000000

and the normalized of them are:

341584.736395270    39652.0303186782    6.02013189864630
341584.829061797    39652.0300984462    6.01961124609511
341584.859110126    39652.0301718569    6.01839639014231
341584.889473648    39652.0300250355    6.01978479694551
341584.920047298    39652.0300250355    6.01700798333912
341584.934125886    39652.0300250355    6.01839639014231
341584.951566525    39652.0303186782    6.01891704269351
341585.029629143    39652.0300984462    6.03609857688303
341585.146355346    39652.0301718569    6.01249566122874
341585.344821410    39652.0300984462    6.01631377993752

Do I have to normalized any column separately?

Upvotes: 0

Views: 310

Answers (1)

herohuyongtao
herohuyongtao

Reputation: 50667

You should use:

max_value = max(A(:));
min_value = min(A(:));
normalizedA = (A - min_value)/(max_value - min_value);

Upvotes: 1

Related Questions