MATLAB: Error using eval function

MATLABtextscan

I am trying simple eval function . But at some times it gets executed fine. Sometimes it gives me the error msg "Error: Unexpected MATLAB expression". Here's the eval function code. I hope i got the syntax correctly. collection is a character array = 'hero','zero','horse','cow'
collection = regexprep(collection,' ',''',''');
eval(['words = {''',collection,'''};']);

Best Answer

Do not use eval() for that.
words = regexp(collection, '\s+', 'split');