MATLAB: Strcmp help

strcmp

How would i strcmp two character strings with different numbers of rows? Also how can i display what the differences are between the two rows?

Best Answer

Like Fangjun said, ismember(),intersect() or setdiff() may be useful.
% Make a cell array of 10 short strings
firstSet = cellstr(char(randi(26,10,4)+96));
% And a second array using some of the first set mixed with other randoms
secondSet = cat(1, firstSet([2,7,9]), cellstr(char(randi(26,10,4)+96)));
% Randomise the order of this second set
secondSet = secondSet(randperm(length(secondSet)));
% Find matches
[firstMatch, firstMatchLocs] = ismember(firstSet,secondSet);
cell2print = cat(1, firstSet(firstMatch)', num2cell([find(firstMatch)'; firstMatchLocs(firstMatch)']));
fprintf('(%s), found at first index %d matches second index %d\n', cell2print{:})
fprintf('The following firstSet entries did not match the secondSet:\n')
cell2print = cat(1, firstSet(~firstMatch)', num2cell(find(~firstMatch)'));
fprintf('(%s) at index %d\n', cell2print{:})