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

Contact us at files@mathworks.com