选择向量中除一个之外的所有元素 [英] Select all elements except one in a vector
问题描述
我的问题非常类似于这一个但我无法确切地知道如何将这个答案应用于我的问题。
My question is very similar to this one but I can't manage exactly how to apply that answer to my problem.
我循环使用变量 k的向量
并且想要选择整个向量,但索引 k
的单个值除外。
I am looping through a vector with a variable k
and want to select the whole vector except the single value at index k
.
任何想法?
for k = 1:length(vector)
newVector = vector( exluding index k); <---- what mask should I use?
% other operations to do with the newVector
end
推荐答案
vector([1:k-1 k + 1:end])
会做。根据其他操作,可能有更好的方法来处理这个问题。
vector([1:k-1 k+1:end])
will do. Depending on the other operations, there may be a better way to handle this, though.
为了完整性,如果你想删除一个元素,你不需要去 vector = vector([1:k-1 k + 1:end])
route,你可以使用 vector(k)= [];
For completeness, if you want to remove one element, you do not need to go the vector = vector([1:k-1 k+1:end])
route, you can use vector(k)=[];
这篇关于选择向量中除一个之外的所有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!