How to exclude min and max only once in a if statement?
    3 次查看(过去 30 天)
  
       显示 更早的评论
    
Can anyone please tell me how when using an if statement and taking the mean of a vector of any size. when I take the mean of the vector I am asked if the vector has more than 6 elements exclude the min and max. But if the min or max occurs more than once only exclude it once.
so far I have ...
function ave = improvedMean(V1)
n = length(V1)
if n>0 %%n<= 5
 sum(V1) / n
elseif n >= 6
     ((sum(v1)-((min(v1)+(max(v1))) / (n-2)
I'm not sure where to go from there..
0 个评论
采纳的回答
  Mohammad Abouali
      
 2014-10-7
        What you did was correct. Just add an "end" at the end of your code and change
if n>0 %%n<= 5
to
if n>0 && n<= 5
更多回答(2 个)
  the cyclist
      
      
 2014-10-7
        
      编辑:the cyclist
      
      
 2014-10-7
  
      function ave = improvedMean(V1)
n = length(V1)
if n <= 5
    ave = sum(V1) / n
else
    ave = (sum(V1)-(min(V1)+max(V1))) / (n-2)
end
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



