不能在 Matlab 中使用 eval

Can not use eval in Matlab

这是我的代码:

 collection = cubsfantony 848 visa/mastercard, money order/cashiers checks

 temp = regexprep(collection,' ',''',''')

%return

temp = cubsfantony','848','visa/mastercard,','money','order/cashiers','checks'  % why?

eval(['words = {''',temp,'''};']); 

和Matlab return如下:

 Error: Unexpected MATLAB expression.

谁能帮帮我?

完全没有必要使用 eval...请不要使用它。这被认为是不好的做法。但是,据我了解,您想拆分所有由 space 分隔的字符串,并将它们放入单独的元胞数组中。您可以使用 strsplit 轻松做到这一点,并使用 space 字符作为拆分分隔符:

collection = 'cubsfantony 848 visa/mastercard, money order/cashiers checks';
out = strsplit(collection, ' ');

我们得到:

>> out = strsplit(collection, ' ')

out = 

  Columns 1 through 4

    'cubsfantony'    '848'    'visa/mastercard,'    'money'

  Columns 5 through 6

    'order/cashiers'    'checks'