Matching combinations of strings
I have a table TT with a string variable TT.name. I want to return true if TT.name matches any entry in another table variable OK.name. However, I have some complications I am having a hard time parsing.
Many of the strings in TT.name are combinations of strings that appear in OK.name. I want to include these as a true match. Sometimes they have a + symbol, sometimes just a space. Further complicating matters, the table OK contains some entries with spaces, and if they do I want to treat them as an entire entry, and not break them up at the spaces.
TT = table(["Green"; "Red"; "Blue"; "Black Blue"; "Black"; "Blue Green"; "Red + Blue"; "Red Orange"; "Red + White"], ‘VariableNames’, {‘name’})
OK = table(["Red"; "Green"; "Blue"; "Black Blue"], ‘VariableNames’, {‘name’})
This is the output I would want, but not by manually changing rows 6 and 7:
TT.match=ismember(TT.name,OK.name);
TT.match(6:7)=1
In the example, "Blue Green" and "Red + Blue" are true matchs, because "Blue" "Green" and "Red" all appear as entries in OK.name.
"Black" is not a match, because the only entry in OK.name is "Black Blue" and I do not want to separate the words from this table.
"Red Orange" and "Red + Orange" are not matches because only "Red" is in the OK table.I have a table TT with a string variable TT.name. I want to return true if TT.name matches any entry in another table variable OK.name. However, I have some complications I am having a hard time parsing.
Many of the strings in TT.name are combinations of strings that appear in OK.name. I want to include these as a true match. Sometimes they have a + symbol, sometimes just a space. Further complicating matters, the table OK contains some entries with spaces, and if they do I want to treat them as an entire entry, and not break them up at the spaces.
TT = table(["Green"; "Red"; "Blue"; "Black Blue"; "Black"; "Blue Green"; "Red + Blue"; "Red Orange"; "Red + White"], ‘VariableNames’, {‘name’})
OK = table(["Red"; "Green"; "Blue"; "Black Blue"], ‘VariableNames’, {‘name’})
This is the output I would want, but not by manually changing rows 6 and 7:
TT.match=ismember(TT.name,OK.name);
TT.match(6:7)=1
In the example, "Blue Green" and "Red + Blue" are true matchs, because "Blue" "Green" and "Red" all appear as entries in OK.name.
"Black" is not a match, because the only entry in OK.name is "Black Blue" and I do not want to separate the words from this table.
"Red Orange" and "Red + Orange" are not matches because only "Red" is in the OK table. I have a table TT with a string variable TT.name. I want to return true if TT.name matches any entry in another table variable OK.name. However, I have some complications I am having a hard time parsing.
Many of the strings in TT.name are combinations of strings that appear in OK.name. I want to include these as a true match. Sometimes they have a + symbol, sometimes just a space. Further complicating matters, the table OK contains some entries with spaces, and if they do I want to treat them as an entire entry, and not break them up at the spaces.
TT = table(["Green"; "Red"; "Blue"; "Black Blue"; "Black"; "Blue Green"; "Red + Blue"; "Red Orange"; "Red + White"], ‘VariableNames’, {‘name’})
OK = table(["Red"; "Green"; "Blue"; "Black Blue"], ‘VariableNames’, {‘name’})
This is the output I would want, but not by manually changing rows 6 and 7:
TT.match=ismember(TT.name,OK.name);
TT.match(6:7)=1
In the example, "Blue Green" and "Red + Blue" are true matchs, because "Blue" "Green" and "Red" all appear as entries in OK.name.
"Black" is not a match, because the only entry in OK.name is "Black Blue" and I do not want to separate the words from this table.
"Red Orange" and "Red + Orange" are not matches because only "Red" is in the OK table. strings, compare, ismember, matching MATLAB Answers — New Questions