failing to normalize columns of matrix from 0 to 1

3 ビュー (過去 30 日間)
CLAIRE
CLAIRE 2025 年 4 月 12 日
回答済み: Image Analyst 2025 年 4 月 12 日
for ii=[2 4 6 8 10 12 14 16 18 20 22 26]
n=(A-min(A(:,ii)))/(max(A(:,ii))-min(A(:,ii)));
end
I have a 526x26 matrix, and I need the data in the even-numbered columns to be between 0 and 1. Using the code above, I am getting numbers slightly above 1 (for example, 1.01977).

採用された回答

Walter Roberson
Walter Roberson 2025 年 4 月 12 日
Perhaps you want something like
n = A;
for ii=[2 4 6 8 10 12 14 16 18 20 22 26]
n(:,ii) = (A(:,ii)-min(A(:,ii)))/(max(A(:,ii))-min(A(:,ii)));
end
Otherwise you are selecting one column at a time to scale against, but you are scaling the entire matrix A against the values from the column, and you are not saving the results either, so the end result is the same as if you had only done for ii=26
  1 件のコメント
CLAIRE
CLAIRE 2025 年 4 月 12 日
That worked, thank you

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2025 年 4 月 12 日
for ii = 2 : 2 : size(A, 2)
A(:,ii) = rescale(A(:,ii), 0, 1);
end

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by