我需要从给定一行要匹配的大型单元格数组中返回匹配项。我写了这段代码,但似乎不应该有这么大的挑战——代码感觉过度劳累。这样做的正确方法是什么?
function locations= MatchRowInHaystack(haystack,needle)
%Returns array locations: where needle matches haystack
%Where Needle is a cell array of identifiers
%And Haystack is a cell array of rows that may match needle.
%Split haystack into cell arrays by row:
rows=mat2cell(haystack,ones(size(haystack,1),1),size(haystack,2));
%Find row in haystack that matches needle row.
locations=find(cellfun(@isequal,rows,repmat({needle},[numel(rows) 1])));
end