I want to normalize just one column, how do i do that ?

4 次查看(过去 30 天)
  1 个评论
Diogo Costa
Diogo Costa 2021-5-20
The colum is the 12 that i want to normalize, i can't find a way to do a code that normalize one or specific columns without changing the others

请先登录,再进行评论。

采纳的回答

Steven Lord
Steven Lord 2021-5-20
format shortg % Changing the display format to make the normalized matrix look nicer
M = magic(6)
M = 6×6
35 1 6 26 19 24 3 32 7 21 23 25 31 9 2 22 27 20 8 28 33 17 10 15 30 5 34 12 14 16 4 36 29 13 18 11
M(:, 4) = normalize(M(:, 4)) % Normalized with 'zscore'
M = 6×6
35 1 6 1.3716 19 24 3 32 7 0.4572 23 25 31 9 2 0.64008 27 20 8 28 33 -0.27432 10 15 30 5 34 -1.1887 14 16 4 36 29 -1.0058 18 11
M([1 3], :) = normalize(M([1 3], :), 2, 'center') % normalize so rows 1 and 3 have mean 0
M = 6×6
20.605 -13.395 -8.3953 -13.024 4.6047 9.6047 3 32 7 0.4572 23 25 16.06 -5.94 -12.94 -14.3 12.06 5.06 8 28 33 -0.27432 10 15 30 5 34 -1.1887 14 16 4 36 29 -1.0058 18 11
[mean(M(1, :)), mean(M(3, :))] % check -- should be close to 0
ans = 1×2
8.8818e-16 1.1842e-15

更多回答(1 个)

Jonas
Jonas 2021-5-20
编辑:Jonas 2021-5-20
use
data(:,12)=data(:,12)/max(abs(data(:,12)));
if your data in column 12 is not negative, then you can leave out the abs() function

标签

Community Treasure Hunt

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

Start Hunting!

Translated by