sum, vector elements, except i-th
Mostra commenti meno recenti
hi,
how can I sum vector elements, say v = rand(1,30), except 12th one?
thanks,
Risposta accettata
Più risposte (1)
some other options:
sum(v([1:11, 13:end]))
sum(v(setdiff(1:end, 12))
This latter one, will also work if you have a set of indices you want to exclude. e.g.:
sum(v(setdiff(1:end, [5 12 18])) %sum of v except elements 5, 12, and 18
1 Commento
mehrdad asadi
il 8 Lug 2015
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!