Update!
We wrote a containers.Map backed list class. Build up the list using the “append” method, and then assign the values to a cell array using “toCell” to iterate them (don’t use valueByIndex). Building up the list is still slow, but iterating is lightning fast! You’ll also need this noop Null class.
As of 2008b Matlab only has one abstract data type built-in: containers.Map. I needed a typical List class, and thought I’d back it with a cell array ala Java’s ArrayList. I was surprised to find that accessing a cell as the property of an object was a huge performance bottleneck.
Mathworks has this to say about passing behavior:
“In the case of passing structures or cell arrays, only the field or cell data being modified by the function will be passed “by value”. When the function returns, (assuming that the modified structure or cell array is returned as an output argument of the function) the calling workspace’s copy of the structure or cell array is replaced by the function’s copy such that only the changed fields are altered. This is done to make copying more efficient.”
Are my slowdowns due to some unnecessary copying? Or is it just the overhead of making method calls? Here are some simple benchmarks:


