Please see the second piece of code snippet from my last blog post . We were able to reduce the execution time of the algorithm from 66.5 msec to 36.5 msec after relying on Preallocation. In this post I want to work on the same algorithm, and see if I can make it more efficient. For this I want to rely on the power of logical expressions and indexing in Matlab. Without too much explanation let me share the code which does this: b = a(a < 0.5); Yes, Thats it! Just one line. :) Let me explain the code. The line (a < 0.5) creates a logical array of 1's and 0's depending on whether the element is less than 0.5 or not. The size of this logical array is same as the size of array 'a'. Suppose if a=[0.01 0.49 0.5 0.8], the logical array would be like this, [1 1 0 0]. The 1's are equivalent to the logical value TRUE and 0's imply a logical value of FALSE. Now, when I write, a(a < 0.5) it means that I am interested in only elements which hav...
Sharing my share of knowledge in the technical world