0
我需要从一个大单元阵列返回匹配,并给出一行匹配。我写了这段代码,但似乎不应该是这样的挑战 - 代码感觉过度。什么是正确的方法来做到这一点?MATLAB在单元阵列中匹配一行,提供了一个样本单元阵列
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