Is there a Matlab function to normalize a vector ?
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Wondering if there is a matlab function to normalize a vector: a is a vector normalize a : a/norm(a)
0 commentaires
Réponses (2)
John D'Errico
le 5 Juin 2016
Modifié(e) : John D'Errico
le 5 Juin 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 commentaires
vahid rowghanian
le 23 Mai 2021
Modifié(e) : vahid rowghanian
le 23 Mai 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 commentaires
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!