need help find the sum of the vector by the function

1 回表示 (過去 30 日間)
Eyad Ramadan
Eyad Ramadan 2020 年 7 月 29 日
コメント済み: Cris LaPierre 2020 年 7 月 29 日
find the sum of the vector by the function

回答 (1 件)

Johannes Hougaard
Johannes Hougaard 2020 年 7 月 29 日
Under the assumption that only one instance of the minimum grade should be replaced, and that the minimum grade should be included in the average:
function total = grades(v)
[~,idx] = min(v);
v(idx) = mean(v); % given that the minimum grade should be part of the calculated average
total = sum(v);
end
If all instances (e.g. both sixes in v = [12 6 6 10 13]) should be replaced
function total = grades(v)
exclude = v == min(v);
v(exclude) = mean(v); % or v(exclude) = mean(v(~exclude)) if minimum should be excluded from calculation;
total = sum(v);
end

カテゴリ

Help Center および File ExchangeNumbers and Precision についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by