Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
910 views
in Technique[技术] by (71.8m points)

matlab - How to normalize / denormalize a vector to range [-1;1]

How can I normalize a vector to the range [-1;1]

I would like to use function norm, because it will be faster.

Also let me know how I can denormalize that vector after normalization?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

norm normalizes a vector so that its sum of squares are 1.

If you want to normalize the vector so that all its elements are between 0 and 1, you need to use the minimum and maximum value, which you can then use to denormalize again.

%# generate some vector
vec = randn(10,1);

%# get max and min
maxVec = max(vec);
minVec = min(vec);

%# normalize to -1...1
vecN = ((vec-minVec)./(maxVec-minVec) - 0.5 ) *2;

%# to "de-normalize", apply the calculations in reverse
vecD = (vecN./2+0.5) * (maxVec-minVec) + minVec

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...