How to normalize a vector considering both maximum and the sum of values?

조회 수: 3 (최근 30일)
Sooraj Narayan
Sooraj Narayan 2019년 12월 19일
편집: Andrei Bobrov 2019년 12월 24일
For instance; I have a vector
A=[
7782
7761
7707
7832
8154
8442
8690
9151
9318
9300 ];
The maximum is 9300 and the sum is 84137. Now I need to normalize this vector so that I get the same shape pattern for a new maximum (say 9900) and new sum (say 8700).

답변 (2개)

Kaashyap Pappu
Kaashyap Pappu 2019년 12월 23일
You can use the normalize function with the ‘range’ method to preserve the shape of your normalized plot. This will consider values in the range [a,b] where a is the minimum value and b is the maximum value. The other methods could also be used as needed.
Hope this helps!

Andrei Bobrov
Andrei Bobrov 2019년 12월 23일
Please run follow m - file:
SN = 8700;
Nmx = 9900;
nmn = fzero(@(x)func1(x,Nmx,SN,A),-10000);
[~,N] = func1(nmn,Nmx,SN,A);
function [dt,N] = func1(Nmn,Nmx,SN,A)
mn = min(A);
N = (Nmx - Nmn)/(max(A) - mn)*(A - mn) + Nmn;
dt = sum(N) - SN;
end
Here N - your output vector.
  댓글 수: 2
Sooraj Narayan
Sooraj Narayan 2019년 12월 24일
Thanks a lot for the reply. But would you kindly mind elaborating on the mathematics behind the code? I am having doubts whether it is actually possible to retain the shape of a vector while normalizing it using the maximum and the sum?
Andrei Bobrov
Andrei Bobrov 2019년 12월 24일
편집: Andrei Bobrov 2019년 12월 24일
subplot(2,1,1)
plot(A,'g-')
subplot(2,1,2)
plot(N,'r-')
fig.png

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by