Is there a Matlab function to normalize a vector ?
24 次查看(过去 30 天)
显示 更早的评论
Wondering if there is a matlab function to normalize a vector: a is a vector normalize a : a/norm(a)
0 个评论
回答(2 个)
John D'Errico
2016-6-5
编辑:John D'Errico
2016-6-5
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 个评论
vahid rowghanian
2021-5-23
编辑:vahid rowghanian
2021-5-23
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!