Find matching rows of cell arrays containing strings
Show older comments
Hi,
I am working with a pair of cell arrays, containing strings. The cell arrays are of the same size, and they contain the same rows, but in different order. E.g.:
A = {'ABC' '123'; 'A' '100'; 'C' '0'};
B = {'A' '100'; 'C' '0'; 'ABC' '123'};
It will always be the case that the rows are simply ordered differently. What I am trying to accomplish is to find this ordering. That is, row 1 in A becomes row 3 in B, row 2 in A becomes row 1 in B, and row 3 in A becomes row 2 in B. So I need some sort of output like:
output = [3 2 1]
or something containing the same kind of information. I just need to know how the rows are permuted. I've tried using cellfun with ismember and so on, but I can't seem to make that handle rows, as opposed to cell by cell. I've also tried converting A and B into arrays numbers (because it's my impression that it's easier to deal with numbers than strings), but then I run into the problem that not all the cells have the same size, so there's a concatenating error.
In short, I've tried a bunch of different cellfun's with strfind, ismember, etc., but I haven't found a method that works for rows specifically.
Any help is greatly appreciated!
Accepted Answer
More Answers (0)
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!