average.m

来自「一个matlab的将军模型」· M 代码 · 共 54 行

M
54
字号
function v_avg = average(V)

% Average value of a vertices object
%
% Syntax:
%   "A = average(vtcs)"
%
% Description:
%   "average(vtcs)" returns a column vector containing the average value
%   of the points represented by "vtcs" (i.e. find the average value of
%   each dimension of "vtcs").
%
% Examples:
%
%
%
%   "a = ["
%
%   "2 2 4 4"
%
%   "1 3 3 1"
%
%   "0 0 0 0];"
%
%   "vtcs = vertices(a);"
%
%   "A = average(vtcs)"
%
%
%
%   returns 
%
%
%
%   "A ="
%
%   "3"
%
%   "2"
%
%   "0"
%
%
%
% See Also:
%   vertices

N = length(V);
v_avg = V.list(:,1);
for k = 2:N
  v_avg = v_avg + V.list(:,k);
end
v_avg = v_avg/N;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?