Normalizing to the maximum value

I have a 48X128 matrix. I want to normalize each row to the maximum value in that row. What function will achieve this?

回答(1 个)

Use normalize() to normalize each row or use simple matrix operation to obtain the values of matrix elements to be between [0 .. 1]:
A = randi(10, 7 , 5) % Data
A = 7×5
8 8 2 7 10 3 2 9 10 7 2 10 1 6 10 2 2 10 5 6 8 9 7 5 8 2 3 9 3 8 2 7 3 6 10
An = normalize(A,2) % Normalize each row
An = 7×5
0.3333 0.3333 -1.6667 0 1.0000 -0.8979 -1.1785 0.7857 1.0663 0.2245 -0.8907 0.9845 -1.1251 0.0469 0.9845 -0.9045 -0.9045 1.5076 0 0.3015 0.3956 1.0550 -0.2638 -1.5825 0.3956 -0.9258 -0.6172 1.2344 -0.6172 0.9258 -1.1217 0.4362 -0.8101 0.1246 1.3710
ANor = A./max(A(1:end,:)) % Normalize wi.r.t. max value of each row
ANor = 7×5
1.0000 0.8000 0.2000 0.7000 1.0000 0.3750 0.2000 0.9000 1.0000 0.7000 0.2500 1.0000 0.1000 0.6000 1.0000 0.2500 0.2000 1.0000 0.5000 0.6000 1.0000 0.9000 0.7000 0.5000 0.8000 0.2500 0.3000 0.9000 0.3000 0.8000 0.2500 0.7000 0.3000 0.6000 1.0000

1 个评论

the normalize function defaults to normalising by 'zscore' . For other options, see the documentation section on method.

请先登录,再进行评论。

类别

产品

版本

R2022b

标签

Community Treasure Hunt

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

Start Hunting!

Translated by