Got Questions? Get Answers.
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:
Find the absolute maximum values in a matrix?

Subject: Find the absolute maximum values in a matrix?

From: Wei He

Date: 26 Oct, 2010 09:44:04

Message: 1 of 5

Hi, frind,

    I am dealing with a matrix with positive or negative values.
 
   here, I need to find the maximum values (Absolute maximum value) in each rows of the matrix A, and comprise a new column vector B. And repeated to do it for many times to comprise a big matrix C, (each colums of C is different B vector.)

   For instance:
    A = [ 1, 3, -9, 8;
            7, 12, -3, 0;
            -7, 6, 0, 3 ]

   so, B = [ -9;
                 12;
                 -7 ]

How to do that? I tried to use:
       max(abs(A),[],2)
but don't know how to deal with the negative sing " - ".

Thanks!!

Wei.

Subject: Find the absolute maximum values in a matrix?

From: Oleg Komarov

Date: 26 Oct, 2010 09:58:03

Message: 2 of 5

"Wei He" <Eric.he@hotmail.com> wrote in message <ia67t4$j8a$1@fred.mathworks.com>...
> Hi, frind,
>
> I am dealing with a matrix with positive or negative values.
>
> here, I need to find the maximum values (Absolute maximum value) in each rows of the matrix A, and comprise a new column vector B. And repeated to do it for many times to comprise a big matrix C, (each colums of C is different B vector.)
>
> For instance:
> A = [ 1, 3, -9, 8;
> 7, 12, -3, 0;
> -7, 6, 0, 3 ]
>
> so, B = [ -9;
> 12;
> -7 ]
>
> How to do that? I tried to use:
> max(abs(A),[],2)
> but don't know how to deal with the negative sing " - ".
>
> Thanks!!
>
> Wei.

[trash,I] = max(abs(A),[],2)
A(sub2ind(size(A),(1:3).',I))

Oleg

Subject: Find the absolute maximum values in a matrix?

From: Wei He

Date: 26 Oct, 2010 10:03:04

Message: 3 of 5

"Wei He" <Eric.he@hotmail.com> wrote in message <ia67t4$j8a$1@fred.mathworks.com>...
> Hi, frind,
>
> I am dealing with a matrix with positive or negative values.
>
> here, I need to find the maximum values (Absolute maximum value) in each rows of the matrix A, and comprise a new column vector B. And repeated to do it for many times to comprise a big matrix C, (each colums of C is different B vector.)
>
> For instance:
> A = [ 1, 3, -9, 8;
> 7, 12, -3, 0;
> -7, 6, 0, 3 ]
>
> so, B = [ -9;
> 12;
> -7 ]
>
> How to do that? I tried to use:
> max(abs(A),[],2)
> but don't know how to deal with the negative sing " - ".
>
> Thanks!!
>
> Wei.

I am now doing it each rows after rows.
find the abosute maximu value in each row and record the [row column] of this value
and then turn back to A, find this value, to put it in each row of column vector of B.
It works , however it seems not so cheap. Since in order to find any column B, I need to search for 256 times.

Is there any simpler way to do it? I mean, directly find the absolute maximu value column by column.

Thanks

Subject: Find the absolute maximum values in a matrix?

From: Wei He

Date: 26 Oct, 2010 10:19:04

Message: 4 of 5

Thanks, Oleg,
    I am checking it!

   Regards
Wei.
"Oleg Komarov" <oleg.komarovRemove.this@hotmail.it> wrote in message <ia68nb$9j9$1@fred.mathworks.com>...
> "Wei He" <Eric.he@hotmail.com> wrote in message <ia67t4$j8a$1@fred.mathworks.com>...
> > Hi, frind,
> >
> > I am dealing with a matrix with positive or negative values.
> >
> > here, I need to find the maximum values (Absolute maximum value) in each rows of the matrix A, and comprise a new column vector B. And repeated to do it for many times to comprise a big matrix C, (each colums of C is different B vector.)
> >
> > For instance:
> > A = [ 1, 3, -9, 8;
> > 7, 12, -3, 0;
> > -7, 6, 0, 3 ]
> >
> > so, B = [ -9;
> > 12;
> > -7 ]
> >
> > How to do that? I tried to use:
> > max(abs(A),[],2)
> > but don't know how to deal with the negative sing " - ".
> >
> > Thanks!!
> >
> > Wei.
>
> [trash,I] = max(abs(A),[],2)
> A(sub2ind(size(A),(1:3).',I))
>
> Oleg

Subject: Find the absolute maximum values in a matrix?

From: Jos (10584)

Date: 26 Oct, 2010 13:37:03

Message: 5 of 5

"Wei He" <Eric.he@hotmail.com> wrote in message <ia67t4$j8a$1@fred.mathworks.com>...
> Hi, frind,
>
> I am dealing with a matrix with positive or negative values.
>
> here, I need to find the maximum values (Absolute maximum value) in each rows of the matrix A, and comprise a new column vector B. And repeated to do it for many times to comprise a big matrix C, (each colums of C is different B vector.)
>
> For instance:
> A = [ 1, 3, -9, 8;
> 7, 12, -3, 0;
> -7, 6, 0, 3 ]
>
> so, B = [ -9;
> 12;
> -7 ]
>
> How to do that? I tried to use:
> max(abs(A),[],2)
> but don't know how to deal with the negative sing " - ".
>
> Thanks!!
>
> Wei.

Here is cryptic oneliner, just for fun ...

B = (max(abs(A.')) .* (2*(abs(min(A.')) < max(A.'))-1)).'

Jos

Tags for this Thread

No tags are associated with 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