I am comparing two binary arrays. I have an array where values can either be one or zero, one if the values are the same and zero if they are not. Please note I am doing other stuff beyond checking, so we don’t need to get into vectorization or the nature of the code.
What is more efficient, using a numerical array or a logical array in MATLAB?
Logical values take up fewer bytes than most numeric values, which is a plus if you’re dealing with very large arrays. You can also use logical arrays to do logical indexing. For example:
One note: If you will be dealing with arrays of zeroes and ones that are very sparse (i.e. very few ones), it may be best to use an array of numeric indices such as you would get from the FIND function.Take the following example: