G Gr
G Gr

Reputation: 6080

normalize mat file in matlab

I have a mat file with a structure that looks like this:

enter image description here

How do I normalize the data and save it as a .dat file (ascii)

Upvotes: 1

Views: 3562

Answers (2)

Jonas
Jonas

Reputation: 74930

I assume that you want to normalize each column.

There are two ways you can normalize:

(1) Set minimum to 0 and maximum to 1

dataset = bsxfun(@minus,dataset,min(dataset));
dataset = bsxfun(@rdivide,dataset,max(dataset));

(2) Set average to zero, standard deviation to 1 (if you don't have the Statistics Toolbox, use mean and std to subtract and divide, respectively, as above).

dataset = zscore(dataset); 

EDIT

Why anyone ever use option 2 to normalize?

When you calculate the difference (dissimilarity) between different data points, you may want to weigh the different dimensions equally. Since dimensions with large variance will dominate the dissimilarity measure, you normalize the variance to one.

Upvotes: 5

cyborg
cyborg

Reputation: 10139

Your normalization:

dataset = dataset-ones(size(dataset,1),1)*min(dataset) % subtract min
dataset = dataset ./ (ones(size(dataset,1),1)*max(dataset)+eps) % divide by max

Upvotes: 0

Related Questions