# How to normalize the values of matrix to make it greater than zero and less than one?

24 views (last 30 days)
Sarah A on 23 Oct 2018
Commented: Walter Roberson on 23 Oct 2018
hello,
ho to normalize the values of a matrix to make it greater than zero and less than one?
regards,

madhan ravi on 23 Oct 2018
Sarah A on 23 Oct 2018
yes I am outside now, I need to try this on my laptop. thanks for answering I will accept the answer if it works.

Matt J on 23 Oct 2018
Edited: Matt J on 23 Oct 2018
B=(A-min(A(:)))/(max(A(:))-min(A(:))) ;

Show 1 older comment
Matt J on 23 Oct 2018
delta=0.01;
B=(A-min(A(:)))/(max(A(:))-min(A(:))) ;
B=B*(1-2*delta)+delta;
Sarah A on 23 Oct 2018
It works! thanks a lot :)
Walter Roberson on 23 Oct 2018
delta = max(eps(A(:));
B=(A-min(A(:))+delta)/(max(A(:))-min(A(:))+delta) ;

madhan ravi on 23 Oct 2018
Edited: madhan ravi on 23 Oct 2018
Try :
Np = normalize(A,'norm',1) % A your matrix

#### 1 Comment

Sarah A on 23 Oct 2018
This error occur:
Undefined function 'normalize' for input arguments of type 'double'.
when I searched about "normalized" function I got this:
function ydata = normalize(this,ydata,Xlims,varargin)
%NORMALIZE Scales Y data to normalized time data range.
%
% Input arguments:
% * YDATA is the Y data to be normalized
% * XLIMS are the X limits for the axes of interest
% * The last argument(s) is either an absolute index or a pair
% of row/column indices specifying the axes location in the
% axes grid.
% Author(s): P. Gahinet
[ns,ny,nu] = size(this.Amplitude);
if ny>0
[ymin,ymax,FlatY] = ydataspan(this.Time,this.Amplitude(:,varargin{:}),Xlims);
ydata = (ydata - (ymin+ymax)/2)/((ymax-ymin)/2+FlatY);
end

Matt J on 23 Oct 2018
Edited: Matt J on 23 Oct 2018
delta=0.01;
B = rescale(A,delta,1-delta);

#### 1 Comment

Sarah A on 23 Oct 2018
The same problem I got this error:
Undefined function 'rescale' for input arguments of type 'double'.

Matt J on 23 Oct 2018
A(:)=0.5;

Show 1 older comment
Matt J on 23 Oct 2018
Yep. Therefore all elements will be >0 and <1 as required.
Sarah A on 23 Oct 2018
no I want to normalize here where the output of normalization is greater than zero and less than one.
Matt J on 23 Oct 2018
But hopefully you can see now how vague that is. There are a million answers.