-
4 Comments
I prefer g(end+1:end+g(gptr))=gptr; to usage of repmat. My machine to solve 1234567 takes 48msec vs 15.4 sec using repmat. repmat has a performance issue with large column replication. Unfortunately score is code size and not time.
totally agree (not to mention the entire 'growing inside a loop' uglyness), cody style is very far from any reasonable coding standard...
That's very interesting. The time difference on my (presumably much older) version of MATLAB is much less. Your method gives me an average time of about 18.8 sec, while repmat gives me an average time of 19.5 sec.
In 2023 my laptop takes 6s to run 1234567 on this code. It takes 8ms on Richard's suggestion. But it's not due to repmat. Matlab is just really slow to concatenate, but for some reason isn't with his method. Using my own fast code that preallocates, replacing what I had with repmat doesn't slow it down by much. But I find it perplexing that y(end+1:end+x) would be slower than y=[y x]. It must have something to do with the way the JIT compiler is interpreting how much it needs to preallocate?
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!