Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
matrix normalization

Subject: matrix normalization

From: Snow White

Date: 22 Apr, 2010 19:09:21

Message: 1 of 5

Hello,

I have a matrix (mxn) and I have to Normalize the matrix by scaling its rows so that they have equal norms.

I have checked balance but that normalizes both row and columns and i have also checked norm. is there a way of doing it?

Bye

Subject: matrix normalization

From: Roger Stafford

Date: 22 Apr, 2010 21:14:21

Message: 2 of 5

"Snow White" <gulesaman@gmail.com> wrote in message <hqq6t1$cui$1@fred.mathworks.com>...
> Hello,
>
> I have a matrix (mxn) and I have to Normalize the matrix by scaling its rows so that they have equal norms.
>
> I have checked balance but that normalizes both row and columns and i have also checked norm. is there a way of doing it?
>
> Bye

  Well then find the norm of each row and divide the row by that. That will make each row norm equal to one. Is that what you had in mind?

 M = M./repmat(sqrt(sum(M.^2,2)),1,n);

Roger Stafford

Subject: matrix normalization

From: Snow White

Date: 22 Apr, 2010 22:26:04

Message: 3 of 5

Hello,

Thank you. what i dont get is that you are suming and doing all operations across the second dimension which is the column. should not they be across the first dimension the rows?:S

Bye
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hqqe7d$i0q$1@fred.mathworks.com>...
> "Snow White" <gulesaman@gmail.com> wrote in message <hqq6t1$cui$1@fred.mathworks.com>...
> > Hello,
> >
> > I have a matrix (mxn) and I have to Normalize the matrix by scaling its rows so that they have equal norms.
> >
> > I have checked balance but that normalizes both row and columns and i have also checked norm. is there a way of doing it?
> >
> > Bye
>
> Well then find the norm of each row and divide the row by that. That will make each row norm equal to one. Is that what you had in mind?
>
> M = M./repmat(sqrt(sum(M.^2,2)),1,n);
>
> Roger Stafford

Subject: matrix normalization

From: Roger Stafford

Date: 23 Apr, 2010 00:06:06

Message: 4 of 5

"Snow White" <gulesaman@gmail.com> wrote in message <hqqids$25b$1@fred.mathworks.com>...
> Thank you. what i dont get is that you are suming and doing all operations across the second dimension which is the column. should not they be across the first dimension the rows?:S
--------------------
  When you stated originally that you were asking for "scaling its rows so that they have equal norms" it is my understanding (and I think that of most other people in CSSM) that you were referring to the norms of *horizontal* rows in the matrix, and by columns you would mean *vertical* columns. If that is what you meant, then for each row the first dimension should stay fixed while the second dimensions varies throughout the row, and the reverse is true for any column. Therefore in adding up the squares of the terms in a row, you want to do the summation along the second dimension. For each row this will give a single sum quantity, and for all the rows a single column of sums. Taking their square roots gives you the needed scaling factors for the corresponding rows. The 'repmat' was done, again along the second dimension, to allow multiplying these scaling factors by entire rows,
(though I believe there may be better ways of accomplishing this last operation.)

Roger Stafford

Subject: matrix normalization

From: Snow White

Date: 23 Apr, 2010 11:56:05

Message: 5 of 5

ok i get it now.. thank you.

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hqqo9e$451$1@fred.mathworks.com>...
> "Snow White" <gulesaman@gmail.com> wrote in message <hqqids$25b$1@fred.mathworks.com>...
> > Thank you. what i dont get is that you are suming and doing all operations across the second dimension which is the column. should not they be across the first dimension the rows?:S
> --------------------
> When you stated originally that you were asking for "scaling its rows so that they have equal norms" it is my understanding (and I think that of most other people in CSSM) that you were referring to the norms of *horizontal* rows in the matrix, and by columns you would mean *vertical* columns. If that is what you meant, then for each row the first dimension should stay fixed while the second dimensions varies throughout the row, and the reverse is true for any column. Therefore in adding up the squares of the terms in a row, you want to do the summation along the second dimension. For each row this will give a single sum quantity, and for all the rows a single column of sums. Taking their square roots gives you the needed scaling factors for the corresponding rows. The 'repmat' was done, again along the second dimension, to allow multiplying these scaling factors by entire rows,

> (though I believe there may be better ways of accomplishing this last operation.)
>
> Roger Stafford

Tags for this Thread

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.

Contact us