Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

Re: improve loop performance

$
0
0
On Thursday, August 29, 2013 6:32:09 AM UTC+12, IceHaven wrote:
> "vmpli" wrote in message <kvlf4g$cu3$1@newscl01ah.mathworks.com>...
>
> > Hi Guys,
>
> >
>
> > I look for ways to improve a loop. Simplified part of the code:
>
> >
>
> > fl = cell(KK,1);
>
> > for kk = 1:KK
>
> > fl{kk} = NaN(10);
>
> > for ix = 1:10
>
> > for iy = 1:10
>
> > [~,fl{kk}(ix,iy)] = function();
>
> > end
>
> > end
>
> > end
>
> >
>
> > Each cell of fl contains a 10x10 double array. For KK above some fifty or hundred, the loop gets very time-consuming.
>
> >
>
> > The "function" is a toolbox function (not distributed with ML) which I can't modify. Anyway, I just wonder if there are some ways how to otherwise arrange the loop or split the problem in smaller portions. I looked in the docs how to programm more efficiently - parfor, vectorization, etc.. There are some examples, but I don't see what of those techniques is relevant to my problem and how I could apply it. So any hints are very appreciated. Thank you.
>
>
>
> so absolutely nothing is getting passed to the function? does that mean all the cell members will have the same value?

And why are you using a cell array?
Why not a numeric array:
ff=NaN(10,10,KK);

But as IceHaven intimates, it entirely comes down to what the arguments for function() are and whether it returns only a scalar, in which case there is no hope of vectorisation and you're stuck with the loops.
But if it can return a vector or (even better) a matrix, you will be able to vectorise.

Viewing all articles
Browse latest Browse all 19628

Trending Articles