
[英]How to find out consecutive sequence of numbers in two different vectors in MATLAB?
[英]How to find repeated cell vectors in matlab?
我有n
不同长度的像元向量,将其称为c{i}
,i = 1,2,...,n。
我想找到与他人相等的c {i},例如:
c{1}=[1 2 3 4 5 6]; c{2}=[1 3 5 7]; c{3}=[2 4 6 8];
c{4}=[1 4 6]; c{5}=[3 7]; c{6}=[2 4 6 8]; c{7}=[1 3 5 7];
我希望我可以用一种简单的方法而不是使用两个循环来找到[2 4 6 8]
和[1 3 5 7]
。
谢谢!
您可以通过unique
方式做到这一点。 您需要将向量转换为字符串,因为unique
只能用于字符串的单元格数组,而不能用于数值向量的单元格数组。 在unique
之后,您可以计算histc
重复多少个字符串(向量),并通过一些索引使您检索相应的向量:
strcell = cellfun(@(e) num2str(e), c, 'uniformoutput', 0); %// convert to strings
[~, ii, jj] = unique(strcell); %// apply unique. Second and third outputs needed
ind = find(histc(jj,min(jj)-.5:max(jj)+.2)>1); %// which appear more than once
result = c(ii(ind)); %// indexing to obtain corresponding original vectors
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.