How to index all but select indices?

后端 未结 2 1835
不思量自难忘°
不思量自难忘° 2020-12-17 17:06

I have an array a=rand(100), I want to get every value except the values at the indices notidx=[2;50]. Is there a clean way to get a a

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-17 17:33

    I don't have anything super clean, but you can do

    a[setdiff(1:end, notidx)]
    

    which is slightly cleaner than what you had, or

    ind = trues(length(a))
    ind[notidx] = false
    a[ind]
    

    which is pretty verbose but very clear.

提交回复
热议问题