Error with Min-Max Scaling
显示 更早的评论
The code below fails due to line 5, Just trying to make simple min max scaling code in range of -1 and 1
t=[ 1 5 6; 8 9 7; 2 4 5];
for i= 1:length(t)
Scale1=(t(:,i)-min(t(:,i)))/(max(t(:,i))-min(t(:,i)));
Scalef(i)=2*Scale1 -1
end
Scaled_data=Scalef
采纳的回答
更多回答(1 个)
t = [ 1 5 6; 8 9 7; 2 4 5]
t2 = normalize(t, 'range', [-1 1])
You can also specify a dimension input.
t3 = normalize(t, 2, 'range', [-1 1])
2 个评论
Kyle Koutonen
2021-4-25
Don't use length on a non-vector especially when you want to iterate over the columns of an array.
M = zeros(5, 4);
L = length(M)
In this case L is the number of rows in M rather than the number of columns.
numRows = size(M, 1)
numCols = size(M, 2)
% If using a sufficiently recent MATLAB
numRows2 = height(M)
numCols2 = width(M)
In this other case, where M2 has more columns than rows, L2 is the number of columns in M2. But size, height, and width will always return the size in a specific dimension regardless of whether the array is a vector, a tall matrix, a wide matrix, or an N-dimensional array.
M2 = zeros(3, 17);
L2 = length(M2)
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!