noob
noob

Reputation: 115

matlab normalized problem

I have 84 sets of data, the 1st set of data was normalized by the code below...The normalize equation is (((N-min)*2)/(max-min))-1)...

%read 1st set of data
N = xlsread('output1.xls','data');    

%normalize the 27 columns
N = bsxfun(@minus,N,min(N,[],1));
N = bsxfun(@times,N,2./max(N,[],1));
N = N - 1;
xlswrite('output1.xls',N,'normdata');

Now, every dataset have 27 columns. From original data of 1st dataset, find out the max and min for each column..so, we have 27 max values and 27 min values for each column...then by using these 27 max values and 27 min values for each column, to normalize the 1st set data and 2nd to 84th dataset...

The code below from b3 answer, however, which is different result from the above code.

N = xlsread('output1.xls', 'data');
minN1 = min(N);
maxN1 = max(N);
N = bsxfun(@minus, N, minN1);
N = bsxfun(@times, N, 2./maxN1);
N = N - 1;
xlswrite('output1.xls',N,'normdata');

May i know what's wrong with the code?

Upvotes: 2

Views: 528

Answers (1)

b3.
b3.

Reputation: 7165

In your example, the first data set is in a file called output1.xls so I'm assuming all your input files are of the form output#.xls. Store the normalization parameters for the first file and then loop over the remaining files repeating the normalization calculation.

N = xlsread('output1.xls', 'data');
minN1 = min(N);
maxN1 = max(N);
N = normalize(N, minN1, maxN1);
xlswrite('output1.xls', N, 'normdata');
for ii = 2:84
    filename = sprintf('output%u.xls', ii);
    N = xlsread(filename, 'data');
    N = normalize(N, minN1, maxN1);
    xlswrite(filename, N, 'normdata');
end

function N = normalize(N, minN1, maxN1)
    N = bsxfun(@times, N 2./(maxN1-minN1));
    N = N - 1;
end

Upvotes: 1

Related Questions