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.
如果
a=[5 8 1 2 6 7 1 4 2 3 7 8]; b=[7 6 3 1 5 4 2 0 1 8 9 4];
然后
a1=[1 7 3]
对应于一个矩阵,d 应该是[3 4 8]
[3 4 8]
d是对应a值的准确位置。我如何找到这个值?
d
a
尝试这个:
c = [] for i = 1:length(a1) index = find(a == a1(i)); c = [c, index(1)] end d = [] for i = 1:length(c) d = [d, b(c(i))] end
输出为 [3 4 8]
希望这可以帮助。
作为一个单行:
arrayfun(@(x) b(find(a == x, 1, 'first')), a1)