Commit 673d68bc authored by Jakob Gabriel's avatar Jakob Gabriel
Browse files

quantity.Discrete: changed constructor, such that init with empty i.e. quantity.Discrete([]) works

parent 038b06a1
......@@ -48,31 +48,23 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
% name-value-pair-syntax in varargin.
% to allow the initialization as object array, the constructor
% must be allowed to be called without arguments
if nargin > 0
% must be allowed to be called without arguments, i.e. nargin == 0.
% Then no parameters are set.
if nargin == 1
% if nargin == 1 it can be a conversion of child-classes or an empty
% object
if isa(valueOriginal, 'quantity.Discrete')
% allows the conversion of a quantity object without
% extra check if the object is already from class
% quantity.Discrete
obj = valueOriginal;
return
end
%% allow initialization of empty objects:
valueOriginalSize = size(valueOriginal);
S = num2cell(valueOriginalSize);
if any(valueOriginalSize == 0)
% If the size is specified in the arguements, it should
% be chosen instead of the default size from the
% valueOriginal.
myParser = misc.Parser();
myParser.addParameter('size', [S{:}]);
myParser.parse(varargin{:});
obj = quantity.Discrete.empty(myParser.Results.size);
return;
else
% empty object. this is neede for instance, to create
% quantity.Discrete([]), which is useful for creating default
% values.
obj = quantity.Discrete.empty(size(valueOriginal));
end
elseif nargin > 1
%% input parser
myParser = misc.Parser();
......@@ -90,6 +82,19 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
myGridName = {myParser.Results.gridName};
end
%% allow initialization of empty objects:
valueOriginalSize = size(valueOriginal);
if any(valueOriginalSize == 0)
% If the size is specified in the arguements, it should
% be chosen instead of the default size from the
% valueOriginal.
myParser = misc.Parser();
myParser.addParameter('size', valueOriginalSize((1+numel(myGridName)):end));
myParser.parse(varargin{:});
obj = quantity.Discrete.empty(myParser.Results.size);
return;
end
%% get the sizes of obj and grid
if iscell(valueOriginal)
if isempty(valueOriginal{1})
......
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