www.gusucode.com > MATLAB2008应用程序接口编程技术源码程序 > MATLAB2008应用程序接口编程技术源码程序/code/第2章/2.4/average.m

    function y = average(x)
        %AVERAGE Mean of vector elements.
        %AVERAGE(X),where X is a vector,is the mean of vector elements.
        %Non-vecor input results in an error.
        [m,n] = size(x);
        if(~((m==1)|(n==1))|(m==1 & n==1))
            error(‘Input must be a vector’)
        end
        y = sum(x)/length(x);%Actual computation