在 Matlab 中计算元胞数组的并集
我有一个元胞数组,其中每个元素都由 id 向量组成。我喜欢计算元胞数组中所有元素的并集。这是我当前的解决方案,但我觉得它可以矢量化或者有一个更优雅的解决方案:
union_ids = union(encounter_ids{1},encounter_ids{2});
for i=3:1:numel(encounter_ids);
union_ids = union(union_ids,encounter_ids{i});
end
I have a cell array where each element consists of a vector of ids. I like to compute the union of all elements in the cell array. This is my current solution, but I feel it can be vectorized or have a more elegant solution:
union_ids = union(encounter_ids{1},encounter_ids{2});
for i=3:1:numel(encounter_ids);
union_ids = union(union_ids,encounter_ids{i});
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果元胞数组元素是行向量,您可以这样做:
相反,如果它们是列向量,则使用:
如果您不确定,或者它们恰好都是(有些是行向量,有些是列),那么您可以强制它们都是列向量:
If the cell array elements are row vectors, you can do this:
instead if they are column vectors, then use:
If you are unsure, or they happen to be both (some are row vectors, some are columns), then you can force them to be all column vectors: