Select all elements except one in a vector

后端 未结 6 821
旧巷少年郎
旧巷少年郎 2021-01-04 02:47

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

6条回答
  •  鱼传尺愫
    2021-01-04 03:29

    Very easy:

    newVector = vector([1:k-1 k+1:end]);
    

    This works even if k is the first or last element.

提交回复
热议问题