フィルターのクリア

matrix normalization in matlab

120 ビュー (過去 30 日間)
jenifer
jenifer 2013 年 1 月 30 日
編集済み: DGM 2022 年 12 月 11 日
hi.. i want normalize a matrix (129 x 128)..please help me with matlab codes

採用された回答

Thorsten
Thorsten 2013 年 1 月 30 日
To normalize a matrix such that all values fall in the range [0, 1] use
Anorm = (A - min2(A))/(max2(A) - min2(A));
  3 件のコメント
Irawati Roy
Irawati Roy 2022 年 12 月 11 日
You missed a dot before the division operation for a 2d matrix
DGM
DGM 2022 年 12 月 11 日
編集済み: DGM 2022 年 12 月 11 日
There ./ is not needed here, since the denominator is a scalar.
That said, there is no function called min2() or max2(), nor can I find evidence that there were functions by those names which have since been removed. Maybe they used to be part of one of the toolboxes.
Alternatively, you could do:
Anorm = (A - min(A(:)))/(max(A(:)) - min(A(:)));
or you could do
Anorm = (A - min(A,[],'all'))/(max(A,[],'all') - min(A,[],'all'));
though the latter option wouldn't have worked circa 2013

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

その他の回答 (3 件)

Matt J
Matt J 2013 年 1 月 30 日
You need to decide how you want to define the amplitude of the matrix first. Maybe you want this
normalized = A/norm(A);
or maybe this
normalized = A/max(abs(A(:)))
  3 件のコメント
jenifer
jenifer 2013 年 1 月 30 日
ya... but how can i get a single value from whole matrix...
Jan
Jan 2013 年 1 月 30 日
Please, jenifer, we have asked you to define "normalization" exactly. It wastes time if we guess what you mean.

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


Jing
Jing 2013 年 1 月 30 日
You can use 'normc' or 'normr' for normalization. 'c' or 'r' stands for columns or rows that you want to normalize.

DGM
DGM 2022 年 12 月 11 日
Since R2018a, you can use normalize() to perform normalization in various different ways.
A = 1:6
A = 1×6
1 2 3 4 5 6
B1 = normalize(A,'range') % default range is [0 1]
B1 = 1×6
0 0.2000 0.4000 0.6000 0.8000 1.0000
B2 = normalize(A,'range',[-1 2]) % but you can specify any range
B2 = 1×6
-1.0000 -0.4000 0.2000 0.8000 1.4000 2.0000
B3 = normalize(A,'zscore','std') % zero-center and scale to have std=1
B3 = 1×6
-1.3363 -0.8018 -0.2673 0.2673 0.8018 1.3363
B4 = normalize(A,'norm',2) % normalize by vector p-norm (default p=2)
B4 = 1×6
0.1048 0.2097 0.3145 0.4193 0.5241 0.6290

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by