diff --git a/+quantity/Discrete.m b/+quantity/Discrete.m index 7ac9ed607f0d72dcc61cc013f69a7eb8813969be..243592df9ad9ad11e76b5804c1d8fb70c8de87d7 100644 --- a/+quantity/Discrete.m +++ b/+quantity/Discrete.m @@ -423,7 +423,8 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ... if nargin == 1 % case 0: no domain was specified, hence the value is requested % on the default grid defined by obj(1).domain. - value = obj.obj2value(obj(1).domain); + value = reshape(cat(numel(obj(1).domain)+1, obj(:).valueDiscrete), ... + [obj(1).domain.gridLength(), size(obj)]); elseif nargin == 2 && (iscell(myDomain) || isnumeric(myDomain)) % case 1: a domain is specified by myDomain as agrid @@ -442,8 +443,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ... for k = 1:length(newGrid) myDomain(k) = quantity.Domain(gridNames{k}, newGrid{k}); end - value = reshape(obj.obj2value(myDomain), ... - [myDomain.gridLength, size(obj)]); + value = reshape(obj.obj2value(myDomain), [myDomain.gridLength, size(obj)]); else % Since in the remaining cases the order of the domains is not % neccessarily equal to the order in obj(1).domain, this is @@ -1086,7 +1086,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ... % at() evaluates the object at one point and returns it as array % with the same size as size(obj). value = reshape(obj.on(point), size(obj)); - end + end % at() function value = atIndex(obj, varargin) % ATINDEX returns the valueDiscrete at the requested index. @@ -1129,7 +1129,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ... value = reshape([value{:}], [outputSize, size(obj)]); end - end + end % atIndex() function n = nargin(obj) % FIXME: check if all funtions in this object have the same @@ -2471,12 +2471,8 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ... % obj2value(obj, myDomain) returns the valueDiscrete in the % form size(value) = [myDomain.gridLength objSize] - v = zeros([numel(obj(1).valueDiscrete), numel(obj)]); - for k = 1:numel(obj) - v(:,k) = obj(k).valueDiscrete(:); - end - - value = reshape(v, [obj(1).domain.gridLength(), size(obj)]); + value = reshape(cat(numel(obj(1).domain)+1, obj(:).valueDiscrete), ... + [obj(1).domain.gridLength(), size(obj)]); if nargin >= 2 && ~isequal( myDomain, obj(1).domain ) % if a new domain is specified for the evaluation of @@ -2484,7 +2480,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ... if obj.isConstant % ... duplicate the constant value on the desired % domain - value = repmat(v, [cellfun(@(v) numel(v), {myDomain.grid}), ones(1, length(size(obj)))]); + value = repmat(value(:).', [myDomain.n, ones(1, ndims(obj))]); else %... do an interpolation based on the old data. indexGrid = arrayfun(@(s) 1:s, size(obj), 'UniformOutput', false); diff --git a/+quantity/Function.m b/+quantity/Function.m index e018b2e8716f2a27b6cc55ef36ad7e94f738eccd..b7b2ed5ef4a8b3af921452096743ee05d92b8c37 100644 --- a/+quantity/Function.m +++ b/+quantity/Function.m @@ -91,13 +91,13 @@ classdef Function < quantity.Discrete end value = reshape( cell2mat(value), [ gridLength(myDomain), size(obj)]); end - end + end % obj2value() function n = nargin(obj) % FIXME: check if all funtions in this object have the same % number of input values. n = numel(obj(1).grid); - end + end % nargin() end % ------------- diff --git a/+unittests/+quantity/testDiscrete.m b/+unittests/+quantity/testDiscrete.m index dcb346c61d96275bbc297721f97a0eef8d6a057a..874fe02655cc8188889b864166c03c08e1a0ff33 100644 --- a/+unittests/+quantity/testDiscrete.m +++ b/+unittests/+quantity/testDiscrete.m @@ -1157,7 +1157,7 @@ bc = permute(bc, [ 1 2 4 3 5 ]); B = quantity.Discrete(b, [Z, T], 'size', [ 2, 2 ]); C = quantity.Discrete(c, [V, T], 'size', [2, 3]); BC = B*C; -testCase.verifyTrue(numeric.near(bc, BC.on)); +testCase.verifyTrue(numeric.near(bc, BC.on())); %% z = linspace(0,1).'; @@ -1189,13 +1189,13 @@ function testOnConstant(testCase) A = [0 1; 2 3]; const = quantity.Discrete(A, quantity.Domain.empty); -C = const.on([1:5]); +C = const.on(1:1:5); for k = 1:numel(A) testCase.verifyTrue( all( A(k) == C(:,k) )); end -end +end % testOnConstant() function testIsConstant(testCase)