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:
Standardizing values in a matrix

Subject: Standardizing values in a matrix

From: Ulrik Nash

Date: 19 Sep, 2010 14:25:05

Message: 1 of 10

Hi Everyone,

Suppose I have a matrix A:

A = [1 10 2 3;20 44 10 100]

Now I wish to create B. Each number in B is equal to the corresponding value in A, divided by the largest number in the row of A to which the number belongs.

In the current example, the highest values in each row of A are:

10 and 100

and B thus becomes:

B = [0.1 1 0.2 0.3;0.2 0.44 0.1 1]

How may I do this neatly?

Regards,

Ulrik.

Subject: Standardizing values in a matrix

From: Walter Roberson

Date: 19 Sep, 2010 15:28:36

Message: 2 of 10

On 19/09/10 9:25 AM, Ulrik Nash wrote:

> Suppose I have a matrix A:
>
> A = [1 10 2 3;20 44 10 100]
>
> Now I wish to create B. Each number in B is equal to the corresponding
> value in A, divided by the largest number in the row of A to which the
> number belongs.

B = A ./ repmat(max(A,2),1,size(A,2));

Subject: Standardizing values in a matrix

From: Bruno Luong

Date: 19 Sep, 2010 15:50:06

Message: 3 of 10

Walter Roberson <roberson@hushmail.com> wrote in message <F_plo.5137$D67.1232@newsfe01.iad>...
>
> B = A ./ repmat(max(A,2),1,size(A,2));

max(A,2) should be replaced with max(A,[],2)

Bruno

Subject: Standardizing values in a matrix

From: Matt J

Date: 19 Sep, 2010 16:39:03

Message: 4 of 10

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <i75bfe$t8e$1@fred.mathworks.com>...
> Walter Roberson <roberson@hushmail.com> wrote in message <F_plo.5137$D67.1232@newsfe01.iad>...
> >
> > B = A ./ repmat(max(A,2),1,size(A,2));
>
> max(A,2) should be replaced with max(A,[],2)
====

And for efficiency's sake, it's best to use bsxfun

B=bsxfun(@rdivide,A,max(A,[],2));

Subject: Standardizing values in a matrix

From: Walter Roberson

Date: 19 Sep, 2010 18:29:17

Message: 5 of 10

On 19/09/10 10:50 AM, Bruno Luong wrote:
> Walter Roberson <roberson@hushmail.com> wrote in message
> <F_plo.5137$D67.1232@newsfe01.iad>...
>>
>> B = A ./ repmat(max(A,2),1,size(A,2));
>
> max(A,2) should be replaced with max(A,[],2)

Now if *I* had designed Matlab...

Subject: Standardizing values in a matrix

From: Bruno Luong

Date: 19 Sep, 2010 18:57:03

Message: 6 of 10

Walter Roberson <roberson@hushmail.com> wrote in message <2Eslo.120630$sL7.86972@newsfe15.iad>...

>
> Now if *I* had designed Matlab...

You wouldn't do more puzzling than :

>> max(1,[])

ans =

     []

>> max(1,[],1)

ans =

     1

>> max([],1)

ans =

     []

>> max([],1,1)
??? Error using ==> max
MAX with two matrices to compare and a working dimension is not supported.
 
% Bruno

Subject: Standardizing values in a matrix

From: Steven_Lord

Date: 20 Sep, 2010 02:20:05

Message: 7 of 10



"Walter Roberson" <roberson@hushmail.com> wrote in message
news:2Eslo.120630$sL7.86972@newsfe15.iad...
> On 19/09/10 10:50 AM, Bruno Luong wrote:
>> Walter Roberson <roberson@hushmail.com> wrote in message
>> <F_plo.5137$D67.1232@newsfe01.iad>...
>>>
>>> B = A ./ repmat(max(A,2),1,size(A,2));
>>
>> max(A,2) should be replaced with max(A,[],2)
>
> Now if *I* had designed Matlab...

If you're going back in time to advise Cleve on how MATLAB should have been
designed, can you give Loren and Steve Eddins a ride so they can give their
$0.02 as well?

http://blogs.mathworks.com/loren/2010/07/09/scalar-roulette/

http://blogs.mathworks.com/steve/2009/08/31/functional-design-clunkers/

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Standardizing values in a matrix

From: Walter Roberson

Date: 20 Sep, 2010 19:36:25

Message: 8 of 10

On 10-09-19 09:20 PM, Steven_Lord wrote:

> If you're going back in time to advise Cleve on how MATLAB should have
> been designed, can you give Loren and Steve Eddins a ride so they can
> give their $0.02 as well?

Odd thing -- you remember in Back To The Future how the Mr. Fusion is fed some
banana skins? Well it turns out that bananas are naturally radioactive because
of their significant potassium (and to a lesser extent, strontium) content.
The article I looked at recently indicated that shipments of bananas not
infrequently set up radioactivity sensors.

Subject: Standardizing values in a matrix

From: Matt J

Date: 20 Sep, 2010 20:00:22

Message: 9 of 10

Walter Roberson <roberson@hushmail.com> wrote in message <i78d88$5sg$1@canopus.cc.umanitoba.ca>...
 
> Odd thing -- you remember in Back To The Future how the Mr. Fusion is fed some
> banana skins? Well it turns out that bananas are naturally radioactive because
> of their significant potassium (and to a lesser extent, strontium) content.
> The article I looked at recently indicated that shipments of bananas not
> infrequently set up radioactivity sensors.
========

Where I work, employees carry dosimeter badges to measure radiation exposure. The badges are collected monthly so that everybody's cumulative monthly dose can be monitored. I've often wondered what kind of blip I could put on my monthly reading if I had a banana for lunch every day...

Subject: Standardizing values in a matrix

From: Matt Fig

Date: 20 Sep, 2010 22:27:04

Message: 10 of 10

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message

Where I work, employees carry dosimeter badges to measure radiation exposure. The badges are collected monthly so that everybody's cumulative monthly dose can be monitored. I've often wondered what kind of blip I could put on my monthly reading if I had a banana for lunch every day...

You too? And I thought I was the only one!

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