Is there a Matlab function to normalize a vector ?
24 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Wondering if there is a matlab function to normalize a vector: a is a vector normalize a : a/norm(a)
0 comentarios
Respuestas (2)
John D'Errico
el 5 de Jun. de 2016
Editada: John D'Errico
el 5 de Jun. de 2016
DEFINITELY.
norma = @(a) a./norm(a);
The point being, if you need a tool that you cannot find, nothing stops you from writing it yourself. That is the power of a language, in that it allows you to extend it in ways that you wish to see it go. Were you to seriously need this tool often, just write as an m-file, and it will be there forever for you to use.
In this case, the solution is so admittedly trivial that there was no need for it to have been provided.
0 comentarios
vahid rowghanian
el 23 de Mayo de 2021
Editada: vahid rowghanian
el 23 de Mayo de 2021
For a 2-D feature vector R that variables are along columns and samples are along rows, use the following code to normalize the feature to unity range (0-1) with respect to min and max values of each column (feature vector).
Rmax = repmat(max(R), size(R,1), 1);
Rmin = repmat(min(R), size(R,1), 1);
R_unity = (R - Rmin)./(Rmax - Rmin);
For normalizing gray or 3-D or more (any number of channel matrices) that contain negative or positive values that need to be confined in unity range (0-1), the code below will help:
im = double(im);
immin = repmat(min(min(im)), size(im,1), size(im,2));
immax = repmat(max(max(im)), size(im,1), size(im,2));
imu = (im - immin)./(immax - immin);
The Matlab function normalize(A), normalizes vector or matrix A to the center 0 and standard deviation 1. The result will be in range (-1,1).
In case by normalization you mean to make the sum of each column to be equal to one, one possible way for matrix D which can even be a multidimensional is:
Dnorm = bsxfun(@rdivide, D, sum(D));
Now, each column summation will be one (see sum(Dnorm) ).
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!