My question is very similar to this one but I can't manage exactly how to apply that answer to my problem.
I am looping through a vector with a variable k
and want to select the whole vector except the single value at index k
.
Any idea?
for k = 1:length(vector)
newVector = vector( exluding index k); <---- what mask should I use?
% other operations to do with the newVector
end
Another alternative without setdiff
() is
vector(1:end ~= k)
vector([1:k-1 k+1:end])
will do. Depending on the other operations, there may be a better way to handle this, though.
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)=[];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With