Thread Subject: Maximum of lower elements in same column (a mix between cumsum and

Subject: Maximum of lower elements in same column (a mix between cumsum and

From: Palle Uldenborg

Date: 7 Jan, 2008 16:20:07

Message: 1 of 1

Exalted masters.

What is the fastest way to do the following?

m=n=l=30;
a=rand(m,n,l);
for i=1:m
  for j=1:n
     for k=1:l
        b(i,j,k)=max(a(1:i,j,k));
     end
  end
end

So in short each element in b should contain the maximum of lower
elements in same column in a. So far my best guess is the following:

m=n=l=30;
a=rand(m,n,l);
b(1,:,:)=a(1,:,:);
for i=2:m
  b(i,:,:)=max(b(i-1,:,:),a(i,:,:));
end

Is it possible to do the operation without using any for-loops at all?

      Thanks in advance

                    Palle

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com