You are on page 1of 4

Matrix normalization - Newsreader - MATLAB Central

Page 1 of 4

Search: MATLAB Central Create Account Log In

File Exchange

Answers

Newsgroup

Link Exchange

Blogs

Trendy

Cody

Contest

MathWorks.com

MATLAB Central > MATLAB Newsreader > Matrix normalization Add thread to My Watch List

What is a Watch List?

Thread Subject: Matrix normalization


Subject: Matrix normalization From: Jerry Date: 29 Jan, 2008 01:34:03 Message: 1 of 10

Tags for this Thread


Reply to this message Add author to My Watch List View original format Flag as spam Separated by commas Ex.: root locus, bode

Everyone's Tags:
normalize

Add a New Tag:


Add

Hi all, Is there a function in Matlab that can normalize a matrix such that values lies within 0 and 1 but not equal to 0? Thank you Subject: Matrix normalization From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) Date: 29 Jan, 2008 04:28:57 Message: 2 of 10

What are tags?


A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest. Anyone can tag a thread. Tags are public and visible to everyone.

Reply to this message Add author to My Watch List View original format Flag as spam

In article <fnlvqb$mri$1@fred.mathworks.com>, Jerry <jerrylcw2004@yahoo.com.hk> wrote: >Is there a function in Matlab that can normalize a matrix >such that values lies within 0 and 1 but not equal to 0? if any(A(:)) NA = (A - min(A(:)) + realmin) ./ (max(A(:))-min(A(:))); else NA = repmat(1/2, size(A)); end This is not quite a linear transformation: adding in realmin has no effect on any value greater than about 1E-306. A -near- equivilent to the above would be: if any(A(:)) NA = (A - min(A(:))) ./ (max(A(:))-min(A(:))); NA(NA==0) = realmin; else NA = repmat(1/2, size(A)); end

If you need a strict linear transform, something like this should work: if any(A(:)) NA = ((A - min(A(:))) ./ (max(A(:))-min(A(:))) + eps) ./ (1 + 2*eps); else NA = repmat(1/2, size(A)); end -So you found your solution What will be your last contribution? -- Supertramp (Fool's Overture) Subject: Matrix normalization From: Yumnam Kirani Singh Date: 29 Jan, 2008 05:23:51 Message: 3 of 10

Reply to this message Add author to My Watch List View original format Flag as spam

If x is your matrix to be normalized then y will be your normalized matrix y=(x-min(min(x)))/(max(max(x))-min(min(x)))

http://www.mathworks.in/matlabcentral/newsreader/view_thread/162772

6/16/2013

Matrix normalization - Newsreader - MATLAB Central

Page 2 of 4

or simply you can use the mat2gray function as y=mat2gray(x); Subject: Matrix normalization From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) Date: 29 Jan, 2008 05:52:20 Message: 4 of 10

Reply to this message Add author to My Watch List View original format Flag as spam

In article <12057079.1201584262553.JavaMail.jakarta@nitrogen.mathforum.org>, Yumnam Kirani Singh <kirani.singh@gmail.com> wrote: >If x is your matrix to be normalized then y will be your normalized matrix >y=(x-min(min(x)))/(max(max(x))-min(min(x))) Not if x has more than two dimensions. That's why I used min(A(:)) and max(A(:)) -- not only saves a function call, but works with any number of dimensions. Also, that form will not work if the matrix is all-zero; that's why I used if any() Also, you have neglected the original poster's condition that the normalized matrix must exclude 0; the normalization you have done will result in 0 at every matrix location that is the same value as the minimum. -'Roberson' is my family name; my given name is 'Walter'. Subject: Matrix normalization From: Yumnam Kirani Singh Date: 29 Jan, 2008 07:07:24 Message: 5 of 10

Reply to this message Add author to My Watch List View original format Flag as spam

A matrix cannot have more than two dimensions. Also, there would not be anyone who would try to normalize a zero or an identity matrix or its multiple. Exluding zero is not a big problem. The following code will work in the way you desire. >>y=(x-min(min(x)))/(max(max(x))-min(min(x)))(1-realmin) + realmin; Or alternatively y=mat2gray(x)*(1-realmin) + realmin; Subject: Matrix normalization From: Steven Lord Date: 29 Jan, 2008 14:46:46 Message: 6 of 10

Reply to this message Add author to My Watch List View original format Flag as spam

"Yumnam Kirani Singh" <kirani.singh@gmail.com> wrote in message news:32773596.1201590475019.JavaMail.jakarta@nitrogen.mathforum.org... >A matrix cannot have more than two dimensions. One generalization that people sometimes make once they have their code working for matrices is to make it work for arrays. Using the a(:) notation means that they don't need to modify that section of their code, and it works for matrices and arrays with more than 2 dimensions. > Also, there would not be anyone who would try to normalize a zero or an > identity matrix or its multiple. If there's one thing I've learned in my time here at The MathWorks, it's to never say something like that. Just about anything that isn't physically impossible to do with MATLAB, I believe someone has tried or will try to do at some point. Are you sure that if you write a function to normalize a matrix or array that no one will ever pass in a zero/constant matrix by accident, or to test the code and try to break it? I wouldn't be. > Exluding zero is not a big problem. The following code will work in the > way you desire. >>>y=(x-min(min(x)))/(max(max(x))-min(min(x)))(1-realmin) + realmin; > > Or alternatively > y=mat2gray(x)*(1-realmin) + realmin; Another alternative, albeit not a one-liner:

function xnorm = normalization(x) xmin = min(x(:)); xmax = max(x(:));

http://www.mathworks.in/matlabcentral/newsreader/view_thread/162772

6/16/2013

Matrix normalization - Newsreader - MATLAB Central

Page 3 of 4

if xmin == xmax % Constant matrix -- I choose to warn and return a NaN matrix warning('normalization:constantMatrix', 'Cannot normalize a constant matrix to the range [0, 1].'); xnorm = nan(size(x)); else xnorm = (x-xmin)./(xmax-xmin); end

-Steve Lord slord@mathworks.com Subject: Matrix normalization From: us Date: 29 Jan, 2008 16:00:22 Message: 7 of 10

Reply to this message Add author to My Watch List View original format Flag as spam

"Steven Lord": <SNIP on the versatility of ML... >> Also, there would not be anyone who would try to normalize a zero or an >> identity matrix or its multiple. > If there's one thing I've learned in my time here at > The MathWorks, it's to never say something like that. > Just about anything that isn't physically impossible to > do with MATLAB, I believe someone has tried or will > try to do at some point... i couldn't agree more with steve! in this department we use ML to have coffee ready on arrival, order pizza in the evening, and mow the lawn in between... and so much more... us Subject: Matrix normalization From: Yumnam Kirani Singh Date: 29 Jan, 2008 16:52:28 Message: 8 of 10

Reply to this message Add author to My Watch List View original format Flag as spam

Nice points! I don't know whether Steve had bad experience of attempting to normalze a zero matrix!! Subject: Matrix normalization From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) Date: 29 Jan, 2008 17:08:17 Message: 9 of 10

Reply to this message Add author to My Watch List View original format Flag as spam

In article <32773596.1201590475019.JavaMail.jakarta@nitrogen.mathforum.org>, Yumnam Kirani Singh <kirani.singh@gmail.com> wrote: >A matrix cannot have more than two dimensions. There are different definitions of Matrix. For example if you google on define:matrix then the first relevant definition (5th overall in the list) is, http://archive.stsci.edu/fits/fits_standard/node11.html A data array of two or more dimensions. More verbosely, http://mathstat.asu.edu/support/doc/unix/coping-with-unix/node188.html A bunch of numbers stored together which can be referenced by one or more subscripts. Single-indexed arrays represent mathematical vectors, double- and higher- indexed arrays represent tensors. Each number in an array is an array element. Most of the meanings of "Matrix" with respect to something physical refer to three dimensional materials, such as, http://imnh.isu.edu/digitalatlas/glossary/letter.asp The relatively fine-grained rock material occupying the space between larger particles in a rock. See also groundmass. http://www.texasbeyondhistory.net/glossary/index.html The sediment or enclosing material within which archeological remains are found. Matrices are often distinguished on the basis of differences in color and texture. ...

http://www.mathworks.in/matlabcentral/newsreader/view_thread/162772

6/16/2013

Matrix normalization - Newsreader - MATLAB Central

Page 4 of 4

http://www.collectionscanada.ca/presses/t15-300-e.html The sunken mould in which type is cast. It is produced by an impression from a punch. -"No one has the right to destroy another person's belief by demanding empirical evidence." -- Ann Landers Subject: Matrix normalization From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) Date: 29 Jan, 2008 17:18:29 Message: 10 of 10

Reply to this message Add author to My Watch List View original format Flag as spam

In article <32773596.1201590475019.JavaMail.jakarta@nitrogen.mathforum.org>, Yumnam Kirani Singh <kirani.singh@gmail.com> wrote: >Exluding zero is not a big problem. The following code will work in the way you desire. >>>y=(x-min(min(x)))/(max(max(x))-min(min(x)))(1-realmin) + realmin; >Or alternatively >y=mat2gray(x)*(1-realmin) + realmin; 1-realmin is going to be 1. Perhaps you meant eps instead of realmin. Also, I believe you accidently omitted a '*' in the first alternative.

-"I will speculate that [...] applications [...] could actually see a performance boost for most users by going dual-core [...] because it is running the adware and spyware that [...] are otherwise slowing down the single CPU that user has today" -- Herb Sutter Tag Activity for This Thread Tag normalize Feed for this Thread
Contact us 1994-2013 The MathWorks, Inc. Site Help Featured MathWorks.com Topics: Patents Trademarks Support Privacy Policy Preventing Piracy Webinars Terms of Use Newsletters MATLAB Trials Careers

Applied By tuba yilmaz

Date/Time 27 Apr, 2010 04:32:27

New Products

Documentation

Training

http://www.mathworks.in/matlabcentral/newsreader/view_thread/162772

6/16/2013

You might also like