"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ii754g$mg3$1@fred.mathworks.com>...
> "Ashley" wrote in message <ii742q$e21$1@fred.mathworks.com>...
> > I have a for loop that I need to convert to cellfun, because the size is very large and it takes too long. This is an example of the for loop:
> >
> > for j=1:length(a)
> > for r=1:size(a,1)
> > if isempty(a{r,j})~=1
> > example{r,j}=( blong{ length( b{1,j} ), j }  a{r,j} );
> > end
> > end
> > end
> >
> > *blong equals b, but with the contents of the 1row cells extracted to many rows of individual values (thus producing empty cells). I want subtract a{r,j} from the maximum value of b{:,j} (it's in ascending order). (and make it negative, of course)
> >
> > I keep getting tripped up due to the size being n x n where neither n is equal to 1.
>
> cellfun and a forloop are often comparable for speed. Is "example" preallocated? That is more than likely your timesink.
>
> example = cell(length(a),size(a,1));
> for j=1:length(a)
> for r=1:size(a,1)
> if ~isempty(a{r,j})
> example{r,j}=( blong{ length( b{1,j} ), j }  a{r,j} );
> end
> end
> end
>
> Good Luck!
> %SCd
>
Thanks, Sean! I didn't realize such a huge difference that would make.
