MATLAB: Find common words in 2 strings

strings

i have 2 string
str1 = ('rabbit is eating grass near a tree');
str2 = ('rabbit is sleeping under tree');
In these 2 strings 'rabbit' 'is' 'tree' is common…. How can i find the common words present in 2 strings….
i want result
str = 'rabbit' 'is' 'tree'

Best Answer

str1 = ('rabbit is eating grass near a tree');
str2 = ('rabbit is sleeping under tree');
str=intersect(strsplit(str1),strsplit(str2))
OR, to maintain the order
str=intersect(strsplit(str1),strsplit(str2),'stable')