Matlab CellFun在函数strfind上 [英] Matlab cellfun on function strfind
本文介绍了Matlab CellFun在函数strfind上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在strfind
函数上使用cellfun
函数在另一个字符串单元格数组中查找字符串的单元格数组中每个字符串的索引,以将其从中排除.
I want to use cellfun
function on strfind
function to find the index of each string in a cell array of string in another cell array of strings to exclude them from it.
strings = {'aaa','bbb','ccc','ddd','eee','fff','ggg','hhh','iii','jjj'};
excludedStrings = {'b','g','h'};
idx = cellfun('strfind',strings,excludedStrings);
idx = cell2mat = idx;
idx = reshap(idx,numel(idx),1);
idx = unique(idx);
strings(cell2mat(idx)) = [];
cellfun
呼叫行中有错误,我该如何解决?
There's error in the cellfun
call line, how can I fix this?
推荐答案
这里很可爱:
strings = regexprep(strings, excludedStrings, '');
故障:
- 要搜索的所有单词/字符都传递给
regexprep
- 此函数用空字符串(
''
)替换上面给出的集合中每次出现的 any 单词/字符.
- All the words/characters to search for are passed on to
regexprep
- This function replaces every occurrence of any word/character in the set given above, with the empty string (
''
).
它将自动对单元格数组string
中的所有元素重复此操作.
It will automatically repeat this action on all elements in the cell-array string
.
如果您还希望从单元格string
中删除任何空字符串,请在上面的命令之后执行此操作:
If you also wish to remove any empty strings from the cell string
, do this after the command above:
strings = strings(~cellfun('isempty', strings));
这篇关于Matlab CellFun在函数strfind上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文