For Programmers: Free Programming Magazines  


Home > Archive > Matlab > January 2008 > Maximum of lower elements in same column (a mix between cumsum and









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Maximum of lower elements in same column (a mix between cumsum and
Palle Uldenborg

2008-01-07, 7:29 pm

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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com