Filter löschen
Filter löschen

Is there a Matlab function to normalize a vector ?

22 Ansichten (letzte 30 Tage)
Carlos Ichikawa
Carlos Ichikawa am 5 Jun. 2016
Bearbeitet: vahid rowghanian am 23 Mai 2021
Wondering if there is a matlab function to normalize a vector: a is a vector normalize a : a/norm(a)

Antworten (2)

John D'Errico
John D'Errico am 5 Jun. 2016
Bearbeitet: John D'Errico am 5 Jun. 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.

vahid rowghanian
vahid rowghanian am 23 Mai 2021
Bearbeitet: vahid rowghanian am 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) ).

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by