arrays - MATLAB中没有for循环的多个数组的交集

标签 arrays matlab cell vectorization intersection

我总是被告知在 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

关于arrays - MATLAB中没有for循环的多个数组的交集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35825435/

相关文章:

javascript - eloquent javascript 关联表 解释

matlab - 从/向 GUIDE/Workspace 保存或加载数据

matlab - 使用 MATLAB 进行自动人脸检测

matlab - Insertshape 在错误的位置绘制 FilledPolygon - Matlab

excel - 将 cell.value 从一个范围传递到另一个子范围

java - java 中的堆空间要求 - Arrays.sort() 与 Collections.sort()

c - 将数据从struct读取到二维数组c中

php - 查找多维数组中的重复值

html - 相对表格单元格中的垂直对齐

excel - 在 Excel 的特定列中突出显示特定单词的代码