更新时间:2023-11-15 15:59:58
要做的是将这个想法封装为一个函数.要么内联:
The thing to do is to encapsulate this idea as a function. Either inline:
substrmatch = @(x,y) ~cellfun(@isempty,strfind(y,x))
findmatching = @(x,y) y(substrmatch(x,y))
或包含在两个m文件中:
Or contained in two m-files:
function idx = substrmatch(word,cellarray)
idx = ~cellfun(@isempty,strfind(word,cellarray))
和
function newcell = findmatching(word,oldcell)
newcell = oldcell(substrmatch(word,oldcell))
所以现在您只需输入
>> findmatching('words',cellArray)
ans =
'nicewords' 'morewords'