Select all elements except one in a vector

后端 未结 6 1001
旧巷少年郎
旧巷少年郎 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:23

    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)=[];

提交回复
热议问题