필터 지우기
필터 지우기

How to finish this function?

조회 수: 1 (최근 30일)
Cristian
Cristian 2014년 5월 4일
답변: Jos (10584) 2014년 5월 4일
function outv=mymean(vec)
mysum=0;
for i=1:length(vec)
mysum=mysum+vec(i);
end
outv=(mysum-max(vec)-min(vec))/(length(vec)-2);
if ismember(vec,unique(vec))==(ismember(unique(vec),vec))
outv=mean(vec);
end
Task: Write a function that will return the mean of the values in a vector, not including the minimum and maximum values. Assume that the values in the vector are unique. It is OK to use the built-in mean function.

채택된 답변

Jos (10584)
Jos (10584) 2014년 5월 4일
Since you may assume that the numbers in the vector are unique you can sum up all numbers (using SUM), subtract the smallest and largest value (using MIN and MAX) and divide by the number of elements minus 2 (using NUMEL or LENGTH).
I leave the coding to you!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by