Showing posts with label speeding up code. Show all posts
Showing posts with label speeding up code. Show all posts

Thursday, February 21, 2008

about logical indexing

Today, M-Lint was telling me that "logical indexing is usually faster than FIND".

I didn't knew what logical indexing means. a short google search and i found this out:

if you want to perform the following operation:

KdP(find( (dP> 1000) & (dP <= 2000) )) = 2;


you can optimize it just by omitting the find command just like this:
KdP( (dP> 1000) & (dP <= 2000) ) = 2;

. Matlab is just capable to handle the "logical indexing" which means the indexes of the vector that match the conditions.

Tuesday, February 12, 2008

use profiler to improve code

there is a very cool application in matlab to help you improve the code. it is called "profiler".
let me give you an example. If you have a script named "name_of_script.m", you can enter the following commands to check it:

profile on, name_of_script, profreport('name_of_script')

at the end, you'll get a new windows, where you can find which section of the script is the bottleneck.

happy coding!