Commit d12565a5 authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

Added input validators to quantity.Discrete to get readable error messages

parent 3a629489
......@@ -72,10 +72,10 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete
%% input parser
myParser = misc.Parser();
myParser.addParameter('gridName', []);
myParser.addParameter('grid', []);
myParser.addParameter('name', string());
myParser.addParameter('figureID', 1);
myParser.addParameter('gridName', [], @(g) isstr(g) || iscell(g));
myParser.addParameter('grid', [], @(g) isnumeric(g) || iscell(g));
myParser.addParameter('name', string(), @isstr);
myParser.addParameter('figureID', 1, @isnumeric);
myParser.parse(varargin{:});
assert(all(~contains(myParser.UsingDefaults, 'gridName')), ...
'gridName is a mandatory input for quantity');
......@@ -220,7 +220,7 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete
for k = 1:size(obj, 3)
A{k} = obj(:,:,k);
end
o = quantity.Operator(A, 'grid', obj(1).grid);
o = quantity.Operator(A);
end
function o = quantity.Symbolic(obj)
......@@ -584,11 +584,18 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete
% invert returns an object containing x = f^-1(y).
% Yet, this is only implemented for obj with one variable
% (grid).
if iscell(gridName)
% fixme: by default the first gridName is chosen as new
% name. This works because the functions is only written
% for quantities with one variable.
gridName = gridName{1};
end
assert(numel(obj(1).gridName) == 1);
assert(isequal(size(obj), [1, 1]));
inverse = quantity.Discrete(repmat(obj(1).grid{obj.gridIndex(gridName)}(:), [1, size(obj)]), ...
'size', size(obj), 'grid', obj.on(), 'gridName', {[obj(1).name]}, ...
'name', gridName);
'name', gridName);
end
......
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