Is there any way to normalize any matrix values to be between (-1) and (1)?

2 visualizzazioni (ultimi 30 giorni)
Hello,
Is there any way to normalize any matrix values to be exactly between (-1) and (1)? I attached the matrix.
regards,

Risposta accettata

Image Analyst
Image Analyst il 12 Gen 2019
You can use mat2gray(), which normalizes data from 0-1 then just scale and subtract 1 to get into the range -1 to +1:
M = 2*mat2gray(M)-1;
A nice single-line solution.
  4 Commenti
Sarah A
Sarah A il 13 Gen 2019
No it is still between -1.0000 and 1.0000, is there any way to fix that ?
Walter Roberson
Walter Roberson il 13 Gen 2019
They would display as -1.0000 and 1.0000 especially with short format in effect, but if you take 1-max(M(:)) and min(M(:))+1 then you will see non-zero residues.

Accedi per commentare.

Più risposte (2)

madhan ravi
madhan ravi il 12 Gen 2019
Modificato: madhan ravi il 12 Gen 2019

Steven Lord
Steven Lord il 12 Gen 2019
Use the normalize function with the 'range' method if you're using release R2018a or later.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by