我总是被告知,在 MATLAB 中几乎所有的 for 循环都可以省略,而且它们通常会减慢进程。那么这里有办法做到这一点吗?
我有一个元胞数组(tsCell
). tsCell
存储不同长度的时间数组。我想为所有时间数组找到一个相交的时间数组(InterSection
):
InterSection = tsCell{1}.time
for i = 2:length{tsCell};
InterSection = intersect(InterSection,tsCell{i}.time);
end
这是另一种方法。这还假设每个原始向量中没有重复项。
tsCell_time = {[1 6 4 5] [4 7 1] [1 4 3] [4 3 1 7]}; %// example data (from Divakar)
t = [tsCell_time{:}]; %// concat into a single vector
u = unique(t); %// get unique elements
ind = sum(bsxfun(@eq, t(:), u), 1)==numel(tsCell_time); %// indices of unique elements
%// that appear maximum number of times
result = u(ind); %// output those elements
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)