# How to normalize vector to unit length

477 ビュー (過去 30 日間)
DSB 2017 年 3 月 11 日
コメント済み: Oleksii Doronin 2021 年 5 月 27 日
how to normalize vector of features to unit length to generate a probability density function (pdf) also what the normalization can do for the vector?

サインインしてコメントする。

### 回答 (3 件)

John D'Errico 2017 年 3 月 11 日

Vector norms are linear, in the sense that for constant k and vector V,
norm(k*V) = k*norm(V)
So all you need do is
V = V/norm(V);
Which will force the norm(V) to now be 1.
Your other question, "what can a norm do for a vector" makes no sense. Sorry. If you can clarify what you mean, I might be able to answer.
##### 3 件のコメント1 件の古いコメントを表示1 件の古いコメントを非表示
John D'Errico 2017 年 3 月 12 日

At the same time, norm is more robust. The computation that Jan shows will fail on some vectors where norm will not.
A very simple example where that is true is:
V = [1e200, 1e190];
norm(V)
ans =
1e+200
sqrt(V*V')
ans =
Inf
Jan 2017 年 3 月 12 日
Thanks, John. I was not aware that norm() uses the stable hypot approach.

サインインしてコメントする。

vahid rowghanian 2021 年 5 月 22 日

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 件のコメント-2 件の古いコメントを表示-2 件の古いコメントを非表示

サインインしてコメントする。

Steven Lord 2021 年 5 月 22 日
The normalize and vecnorm functions may also be of use to you.
##### 1 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
Oleksii Doronin 2021 年 5 月 27 日
Function normalize does not give the needed answer. Instead, it treats vector as a set of points, then centers it around 0 and then normalizes.

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeImage Transforms についてさらに検索

### Community Treasure Hunt

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

Start Hunting!

Translated by