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:
can i improve on the max command to pick the largest element of each column in a big matrix?

Subject: can i improve on the max command to pick the largest element of each column in a big matrix?

From: Joao Ejarque

Date: 29 Aug, 2011 13:41:11

Message: 1 of 3

I have a code that takes the max of large matrices [m by n] many (many) times, and where m is a large number, say m = 4000 (4 thousand) and n = 500.

I have a fairly good piece of code already, but when I get to these matrices, I am just using the max command to get the [1 by n] vectors i need.

Is there a more efficient way, of picking the max in each column, than the max command?

I think each column is a collection of numbers ordered "monotonically" in an inverted U pattern, so that I was wondering whether there is a golden search type procedure that could speed things up here.

Thanks

Joao

Subject: can i improve on the max command to pick the largest element of each column in a big matrix?

From: John D'Errico

Date: 29 Aug, 2011 14:22:11

Message: 2 of 3

"Joao Ejarque" <jme@dreammodel.dk> wrote in message <j3g4tn$c92$1@newscl01ah.mathworks.com>...
> I have a code that takes the max of large matrices [m by n] many (many) times, and where m is a large number, say m = 4000 (4 thousand) and n = 500.
>
> I have a fairly good piece of code already, but when I get to these matrices, I am just using the max command to get the [1 by n] vectors i need.
>
> Is there a more efficient way, of picking the max in each column, than the max command?
>
> I think each column is a collection of numbers ordered "monotonically" in an inverted U pattern, so that I was wondering whether there is a golden search type procedure that could speed things up here.
>

No, there is no already written function that assumes a pattern
exactly as you have, and then computes the maximum element
in each column.

But why not try it yourself? My guess is that you will not be
successful, that the looping overhead and multiple operations,
comparisons, matrix indexing, etc., will in combination cost
more than the single call to an optimized piece of code.
Nothing stops you from trying though.

John

Subject: can i improve on the max command to pick the largest element of each column in a big matrix?

From: Matt J

Date: 29 Aug, 2011 15:26:26

Message: 3 of 3

"Joao Ejarque" <jme@dreammodel.dk> wrote in message <j3g4tn$c92$1@newscl01ah.mathworks.com>...
>
> I think each column is a collection of numbers ordered "monotonically" in an inverted U pattern, so that I was wondering whether there is a golden search type procedure that could speed things up here.
==================

I don't know about golden search, but you might check to see if this tool is applicable to what you are doing

http://www.mathworks.com/matlabcentral/fileexchange/24641-vectorized-find-with-first-option

If there's some costless change to the way you generate your data so that instead of generating the inverse U, you generate its derivative, then you can use the FEX tool to find the first instance (columnwise) where the derivative drops below zero. This will be the max.

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