performance - Compare two cell arrays for identical rows - MATLAB -
I have a cell string matrix with lines 40,000
and a 400
. I need to find the row (rows) in the first
matrix which corresponds to the second
. Please note that there may be several recursive.
It looks like: 40,000
lines like
Anna Frank Anna George Jane Peter Anna George Jane Peter etc.
Here I got the
advanced George Jane Peter
The only way was to find two For
between functions and a if
but it is quite slow: for i = 2:
size: big size, 1) For j = 1: size (small, 1) if zodiac (member (large table (i, 1: 2)), smallest (j, 1: 2))) == 2 total_r (size (total_r, 1) + 1,1) = i; Finally end
I assume that your input is set in this way -
'' '' Anna '' Frank '' Anna '' George '' Jane '' Peter 'Anna' 'George' 'Jane' 'Peter' 'Little' 'Anna' 'George' 'Jane' 'Your To solve the case, two methods can be suggested here.Approach # 1
ismember
based approach -
total_r = search (amount) (Large Tables, Shorty, 'Rows'), 2) == 2)
Approach # 2
% / / Assign a unique label for each cell in both small and large cell arrays, so that you would have to deal with numerical arrays later in% // and you were slowing down% // that there is no mess with the cell arrays. [Unqbig, matches1, idx] = unique ([ BigTable (:); smallTable (:)) big_labels = reshape (idx (1: newzell), size (bigtable) small_labels = reshape (idx (numel (bigtable) +1: end), size (smallTable) )% / Find out which rows from small_labels exactly match the big_labels total_r = get (ismember (big_labels, small_labels, 'rows'))
or that Change ismember
to the last line with the implementation of bsxfun
based
total_r = search (any) (all (BSXfan (@ eq, big_labels, permute (Small_labels, [3 2 1]), 2), 3))
Output from these inputs case for these input -
total_r = 2 3 4 5
Comments
Post a Comment