Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to optimize MATLAB loops?

I have been working lately on a number of iterative algorithms in MATLAB, and been getting hit hard by MATLAB's performance (or lack thereof) when it comes to loops. I'm aware of the benefit of vectorizing code when possible, but are there any tools for optimization when you need the loop for your algorithm?

I am aware of the MEX-file option to write small subroutines in C/C++, although given my algorithms, this can be a very painful option given the data structures required. I mainly use MATLAB for the simplicity and speed of prototyping, so a syntactically complex, statically typed language is not ideal for my situation.

Are there any other suggestions? Even other languages (python?) which have relatively painless matrix tools are an option.

like image 405
user262063 Avatar asked Dec 04 '22 13:12

user262063


1 Answers

It was once true that vectorization would improve the speed of your MATLAB code. However, that is largely no longer true with the JIT-accelerator

This video demonstrating the MATLAB profiler might help.

like image 192
MatlabDoug Avatar answered Dec 29 '22 07:12

MatlabDoug