採用された回答

Mona
Mona 2015 年 7 月 8 日

4 投票

You can always do the sum, then subtract that single element, 12th, from the sum.
v = rand(1,30);
sum_except12=sum(v)-v(12)

1 件のコメント

mehrdad asadi
mehrdad asadi 2015 年 7 月 8 日
oh good point :) thanks

サインインしてコメントする。

その他の回答 (1 件)

Guillaume
Guillaume 2015 年 7 月 8 日
編集済み: Guillaume 2015 年 7 月 8 日

3 投票

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 件のコメント

mehrdad asadi
mehrdad asadi 2015 年 7 月 8 日
Guillaume,
your answers are always different.
thanks and regards,

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange で Multidimensional Arrays についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by