gpt4 book ai didi

matlab - 使用索引矩阵取反精确索引检索矩阵的元素?

转载 作者:行者123 更新时间:2023-12-02 05:20:31 27 4
gpt4 key购买 nike

例如,我有 A=[11 24 33 47 52 67] 并且我有索引矩阵 I = [2 3] 所以我想要元素A 的索引不是 I 给出的索引。所以我想要 B = [11 47 52 67]。我该怎么做并使用 I 作为否定索引矩阵?

最佳答案

去吧

  idx = logical(ones(size(A)));   % // all indices here

或者,正如@Gunther Struyf 所建议的那样,

  idx = true(size(A));

然后

  idx(I) = 0;                       % // excluding not desired indices    
B = A(idx); % // selection

或者

 B = A;
B(I) = [];

关于matlab - 使用索引矩阵取反精确索引检索矩阵的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13918790/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com