How to normalize data between 0 and 1
조회 수: 225 (최근 30일)
이전 댓글 표시
Hello everyone, i hope you are doing well.
I have the following data.
I want to normalize the data between 0 and 1
How can i do that
댓글 수: 0
답변 (3개)
Davide Masiello
2022년 3월 3일
Given the matrix A that you want to normalise, you could write
A = A/max(A(:));
댓글 수: 1
Image Analyst
2022년 3월 3일
He wants the output to go between 0 and 1. Your code will not put the min at 0 unless it is already 0. The easiest solution is to just use
A = rescale(A, 0, 1);
Sinan Islam
2025년 2월 23일
X_max = max(X);
X_min = min(X);
X_scaled = (X - X_min) ./ (X_max - X_min); % scales X to [0, 1]
댓글 수: 1
Walter Roberson
2025년 2월 24일
That does not work if X consists of identical values
X = [1 1 1 1]
X_max = max(X);
X_min = min(X);
X_scaled = (X - X_min) ./ (X_max - X_min) % scales X to [0, 1]
rescale(X)
The code also produces questionable values if the maximum is inf but the points are not all identical
X = [1 2 inf]
X_max = max(X);
X_min = min(X);
X_scaled = (X - X_min) ./ (X_max - X_min) % scales X to [0, 1]
rescale(X)
If one of the input values is -inf then the code produces all NaN
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!