我在谷歌搜索了很多,但没有找到一个帮助我的答案而不会降低我的表现。
我有一个相同大小的Matrice A和B,它们的值不同。然后我想过滤:
indices=find(A<5 & B>3)
A(indices)=
B(indices)=
现在我想对索引应用一个函数 - &gt; indices_2=find(A>=5 | b<=3)
没有再次使用整个矩阵find
和A
上的B
函数。在这种情况下,逻辑操作是不可能的,因为我需要索引而不是0
和1
。
类似的东西:
A(~indices)=
B(~indices)=
而不是:
indices_2=find(A>=5 | B<=3)
A(indices_2)=
B(indices_2)=
之后我想再次拆分这些套装....只是过滤。
我使用indices_2=setdiff(indices, size(A))
但它确实搞砸了我的计算性能。是否有其他方法可以在不使用find
两次的情况下将矩阵拆分为子集?
希望您了解我的问题并符合规定。
答案 0 :(得分:0)
我不明白为什么你不能再次使用find
,也不知道为什么你不能在这种情况下使用逻辑索引但我想如果你要限制自己这样你就可以完成这使用setdiff
:
indices_2 = setdiff(1:numel(A), indices)
然而,如果你担心性能,你应该坚持逻辑索引:
indices = A<5 & B>3
A(indices)=...
B(indices)=...
A(~indices)=...
B(~indices)=...
答案 1 :(得分:0)
我想你可能正在寻找这样的东西:
%Split your data in two and keep track of which numbers you have
ranks = 1:numel(A);
indices= find(A<5 & B>3);
% Update the numbers list to contain the set of numbers you are interested in
ranks_2 = ranks(~indices)
% Operate on the set you are interested in and find the relevant ranks
indices_2= A(~indices)>=5 | B(~indices)<=3
ranks_2 = ranks_2(indices_2)