Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下内容:
X = [1 5; 2 5; 3 7; 4 7; 5 2; 6 7]; X = 1 5 2 5 3 7 4 7 5 2 6 7 b = [1;4;6]; b = 1 4 6
有没有办法查找值(来自 X),输入为 b,输出以下内容:
b1 = 1 5 4 7 6 7
退房INTERSECT。
INTERSECT
[~,index] = intersect(X(:,1),b) b1 = [b X(index,2)];
如果您确定 的值b在 的范围内X:
b
X
c = X(b,:);
或者如果第一列X不是1:N:
1:N
[~,idx]=ismember(b,X(:,1)); idx(idx==0)=[]; c = X(idx,:);