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.
我有一个简单的问题。
假设我们有两个数组:
data = [1 1 2 2 2 2 3 3 3 4 4 4 4 4 5 5 5 5 6 6 6]; A = [1 3 6];
我希望数据中的值索引等于 A 中的任何值。
即答案将是:1、2、7、8、9、19、20、21
如何在不使用 for 循环并一一扫描 A 中的每个值的情况下做到这一点..?谢谢!艺术。
这将完全做到这一点:
inds = find(ismember(data, A))
该函数ismember将找到其中的所有data元素A。的第二个输出ismember也可能有用:
ismember
data
A
>> [~, b] = ismember(data, A)) ans = 1 1 0 0 0 0 2 2 2 0 0 0 0 0 0 0 0 0 3 3 3
其中1,2并3引用索引入A.
1
2
3