ismember returns incorrect results with long nx1 cell array
2 views (last 30 days)
Show older comments
Hey,
I have a cell array of strings(<=50000 elements): strings_array = {50000,1}
the values of the strings all come from the following subset: all_poss_values = {'0' '1' '>1' '>10'}
I am using ismember in a loop to build up a logic vector.
for i=1:length(strings_array)
logic_vector = ismember(strings_array{i,1},all_poss_values(or just '1' etc.))
end
For the most part, this approach works. However on some string arrays the ismember function does not return correct results all the time. For example if I want to build a logic vector showing the position of all 1's in the input cell array, ismember will get 95% of the 1's correctly but will miss out on 5%.
Any ideas why this might be happening? The issue is noticed only on certain input arrays which leads me to believe that there is something weird with the formatting of those arrays however all the arrays should contain identical values.
Best Regards.
0 Comments
Answers (1)
Jan
on 6 Mar 2013
Without doubt ismember() works accurately. Therefore I'm convinced, that the bug is in the code you have only paraphrased roughly. Therefore we cannot guess the cause of the problem.
Do you really mean strings_array{i,i}, or strings_array{i}?
When there are only 4 possible symbols but 50'000 strings, it would be much faster to loop over the 4 symbols instead.
Another approach for cross-checking: FEX: CStrAinBP . This can be much faster than ismember, intersect, setdiff etc.
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!