ismember checks for cell-array or matrix elements. How do we check for string-numeric elements together? Please see below:
cell1 = {'netincome' [1] ; 'equity' [2] } ;
cell2 = { 'cogs' [2222] [1] ; 'equity' [3501] [2] ;
'equity' [3333] [1] ; 'netincome' [1751] [1] } ;
This fails ->ismember(cell1(:,[1 2]), cell2(:,[1 3]) % I know why it fails.
Is there any way to match string elements and numeric elements from 2 cells? I tried using ismember independently (cell2mat func was used) but still can’t hit the right answer. The desired answer is:
[1751 ; 3501] ; OR 'netincome' [1751] [1] ; 'equity' [3501] [2]
I don’t think there’s any good built-in solution for this situation. The best one I can think up at the moment is to create two nested loops to compare all the rows of each cell array, using the function ISEQUAL to do the comparisons:
The result will be a set of match indices in the N-by-1 vector
index, where N is the number of rows incell1. If a row ofcell1can’t be matched to the data in any row ofcell2, then the corresponding entry ofindexwill be 0. Indices of matches inindexwill preserve the original order of the data incell1. Also, this code ignores multiple matches incell2, returning only the index of the first match found and breaking the inner loop (which will potentially reduce the number of iterations needed).Now you can index into
cell2to get the data corresponding to what’s incell1: