Commit aa168de4 authored by Jakob Gabriel's avatar Jakob Gabriel
Browse files

quantity.Discrete.mean: 'all' option implemented

parent c2b849c7
......@@ -2282,10 +2282,21 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
'size', size(obj));
end % imag()
function meanValue = mean(obj)
% mean returns the mean value of all elements of A over all
% variables as a double array.
meanValue = reshape(mean(obj.on(), 1:obj(1).nargin), size(obj));
function meanValue = mean(obj, dim)
% mean(dim) returns the mean value over all domain as a double array
% of the size of obj.
%
% mean(obj, 'all') returns the mean value of all elements of A over all
% domain as a scalar double.
arguments
obj;
dim = [];
end
if strcmp(dim, "all")
meanValue = mean(obj.on(), 'all');
else
meanValue = reshape(mean(obj.on(), 1:obj(1).nargin), size(obj));
end
end
function medianValue = median(obj)
......
......@@ -12,6 +12,14 @@ testCase.TestData.sym.t = t;
testCase.TestData.sym.sy = sy;
end
function testMean(tc)
z = quantity.Domain("z", linspace(0, 1, 11));
x = quantity.Discrete(z.grid, "domain", z);
tc.verifyEqual(mean(x), mean(x.on()));
tc.verifyEqual(mean([1, 0; 0, 2] * x), 0.5*[1, 0; 0, 2]);
tc.verifyEqual(mean([1, 0; 0, 2] * x, 'all'), 3/4/2);
end % testMean()
function testIszero(tc)
z = quantity.Domain("z", linspace(0, 1, 11));
zeta = quantity.Domain("zeta", linspace(0, 1, 11));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment