How to normalize a vector considering both maximum and the sum of values?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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).
0 commentaires
Réponses (2)
Kaashyap Pappu
le 23 Déc 2019
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!
0 commentaires
Andrei Bobrov
le 23 Déc 2019
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 commentaires
Andrei Bobrov
le 24 Déc 2019
Modifié(e) : Andrei Bobrov
le 24 Déc 2019
subplot(2,1,1)
plot(A,'g-')
subplot(2,1,2)
plot(N,'r-')
![fig.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/257028/fig.png)
Voir également
Catégories
En savoir plus sur Subplots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!