I have a large alphabetically ordered cell array of strings (~495 thousand), with lots of duplicates (which are next to each other, because it’s alphabetical).
For a given look-up string, I need to find all the strings in the list which will match the one I pass in.
I’ve been using strcmp(lookUpString,list) to do this, but this is extremely slow– I think it’s going through each value in the list to compare, because it doesn’t know it’s alphabetically sorted.
I could write a while loop to iterate through the list to compare each string using strcmp until I find the block of strings I want (and then stop), but I was wondering if there was a “matlab” way of doing this (i.e. performing logical comparison operations on a sorted array).
Thanks for your help!
UPDATE: I was not satisfied with my earlier “Method 3” so I’ve just re-jigged it a little to get better performance. It now runs almost 10 times faster than a naive
strcmp.strcmpwins on my machine (2011b on Linux Mint 12). In particular, it works much better thanismember. However, you can gain a bit of an extra speed up if you do some manual presorting yourself. Consider the following speed test:The output is: