www.gusucode.com > fixedpoint 案例源码程序 matlab代码 > fixedpoint/SumofVectorElementsExample.m

    %% Sum of Vector Elements  

% Copyright 2015 The MathWorks, Inc.


%% 
% Create a |fi| vector, and specify |fimath| properties in the constructor. 
A =  fi([1 2 5 8 5], 'SumMode', 'KeepLSB', 'SumWordLength', 32)  

%% 
% Compute the sum of the elements of |A|. 
S = sum(A) 

%%
% The output |S | is a scalar with the specified |SumWordLength| of 32.
% The |FractionLength| of |S| is 11 because |SumMode| was set to |KeepLSB|.