Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is arrayfun ever faster than looping?

665 views
Skip to first unread message

John Y

unread,
Sep 11, 2009, 7:04:04 AM9/11/09
to
I timed some of the operations that I did with arrayfun, and compared them to equivalent looping operations. I'm actually getting worse results with arrayfun.

Is this normal? Should I change all my arrayfun operations to loops?

Bruno Luong

unread,
Sep 11, 2009, 7:49:01 AM9/11/09
to
"John Y" <spar...@gmail.com> wrote in message <h8dar4$n9v$1...@fred.mathworks.com>...

> I timed some of the operations that I did with arrayfun, and compared them to equivalent looping operations. I'm actually getting worse results with arrayfun.
>
> Is this normal? Should I change all my arrayfun operations to loops?

Yes, it is normal. Change if speed if your priority.

See similar topic on CELLFUN:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/253815

Arrayfun and cellfun essentially are for-loops with extra overhead. Cellfun can be a fast for few cases (see the post above). Things doesn't seem to change with 2009B.

Bruno

John Y

unread,
Sep 11, 2009, 8:22:03 AM9/11/09
to
Okay, thanks.

So... Why does arrayfun exist at all, then? Are there any advantages?

"Bruno Luong" <b.l...@fogale.findmycountry> wrote in message <h8ddfd$h50$1...@fred.mathworks.com>...

Bruno Luong

unread,
Sep 11, 2009, 8:30:20 AM9/11/09
to
"John Y" <spar...@gmail.com> wrote in message <h8dfdb$s24$1...@fred.mathworks.com>...

> Okay, thanks.
>
> So... Why does arrayfun exist at all, then? Are there any advantages?

Compactness of the code I guess. We can call it as the input of another function, this is of course not possible with for-loop.

Bruno

0 new messages