MATLAB: How toget a list from multiple rows

cell arraysstrings

Hi guys, I have a multiple rows of strings and I want get words that contains "#" all in a single column.
Example:
data = {'he is #coming #today'; 'will #it rain?'};
The desired output:
out = {'#coming';
'#today';
'#it'}
Thanks

Best Answer

Perhaps these are cell strings:
data = {'he is #coming #today'; 'will #it rain?'};
words = strsplit(sprintf('%s ', data{:}), ' ').';
hasHash = ~cellfun('isempty', strfind(words, '#'));
result = words(hasHash);
There are many other ways. Does the # appear anywhere in the word? The example looks like it is the first character in all cases. Then:
data = {'he is #coming #today'; 'will #it rain?'};
words = strsplit(sprintf('%s ', data{:}), ' ').';
result = words(strncmp(words, '#', 1));
Or:
results = setdiff(words, strrep(words, '#', '*')).'