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:
largest magnitude of rows

Subject: largest magnitude of rows

From: Hosein

Date: 14 Mar, 2009 20:54:01

Message: 1 of 7

Is there any function that can choose the largest magnitude of each row in matrix "A"?

e.g.: A=[ 1 0 3 4;-8 3 7 1;2 3 -1 1]
        B=?(A)= [4;-8;3]

Subject: largest magnitude of rows

From: Roger Stafford

Date: 14 Mar, 2009 22:53:02

Message: 2 of 7

"Hosein" <Kalaeimh@yahoo.com> wrote in message <gph5h9$rod$1@fred.mathworks.com>...
> Is there any function that can choose the largest magnitude of each row in matrix "A"?
>
> e.g.: A=[ 1 0 3 4;-8 3 7 1;2 3 -1 1]
> B=?(A)= [4;-8;3]

 [t,p] = max(abs(A),[],2);
 n = size(A,1);
 B = A((1:n)'+n*(p-1));

Roger Stafford

Subject: largest magnitude of rows

From: Jos

Date: 15 Mar, 2009 12:22:01

Message: 3 of 7

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gphcge$jgv$1@fred.mathworks.com>...
> "Hosein" <Kalaeimh@yahoo.com> wrote in message <gph5h9$rod$1@fred.mathworks.com>...
> > Is there any function that can choose the largest magnitude of each row in matrix "A"?
> >
> > e.g.: A=[ 1 0 3 4;-8 3 7 1;2 3 -1 1]
> > B=?(A)= [4;-8;3]
>
> [t,p] = max(abs(A),[],2);
> n = size(A,1);
> B = A((1:n)'+n*(p-1));
>
> Roger Stafford

or

B = max([A -A],[],2)

Jos

Subject: largest magnitude of rows

From: Matt Fig

Date: 15 Mar, 2009 14:46:01

Message: 4 of 7

"Jos " <#10584@fileexchange.com> wrote in message
> or
>
> B = max([A -A],[],2)
>
> Jos

Except that this returns the same as

B = max(abs(A),[],2)

and the OP apparently wants the signs preserved.

B = [4,-8,3]





ubkaff[Wu_eb]uo;YW|uuulWuee6cj|ecWX^[Y[WCk[$j0^OWWjXd_^deeu

Subject: largest magnitude of rows

From: Steven Lord

Date: 15 Mar, 2009 15:23:38

Message: 5 of 7


"Matt Fig" <spamanon@yahoo.com> wrote in message
news:gpj4b9$kgm$1@fred.mathworks.com...
> "Jos " <#10584@fileexchange.com> wrote in message
>> or
>>
>> B = max([A -A],[],2)
>>
>> Jos
>
> Except that this returns the same as
>
> B = max(abs(A),[],2)
>
> and the OP apparently wants the signs preserved.
>
> B = [4,-8,3]

[B, ind] = max(abs(A), [], 2);
for k = 1:size(A, 1)
    B(k) = A(k, ind(k));
end

You could vectorize this loop, but B is preallocated already (from the MAX
call) and it's easy enough to understand, so I'm not going to bother.

--
Steve Lord
slord@mathworks.com

Subject: largest magnitude of rows

From: Jos

Date: 15 Mar, 2009 21:06:01

Message: 6 of 7

"Matt Fig" <spamanon@yahoo.com> wrote in message <gpj4b9$kgm$1@fred.mathworks.com>...
> "Jos " <#10584@fileexchange.com> wrote in message
> > or
> >
> > B = max([A -A],[],2)
> >
> > Jos
>
> Except that this returns the same as
>
> B = max(abs(A),[],2)
>
> and the OP apparently wants the signs preserved.

Hmm, apparently matlab and no sleep do not go well together ... thanks for correcting me, Matt!

Jos

Subject: largest magnitude of rows

From: Matt Fig

Date: 15 Mar, 2009 21:59:02

Message: 7 of 7

"Jos " <#10584@fileexchange.com> wrote in message
> Hmm, apparently matlab and no sleep do not go well together ...


A fact I am well acquainted with myself!



_jqqe^$^l=^$l|lkqdfhslv_|li7b^e|||bl^kbi|VfbJB`|mej|m^rr+^`

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