From 673d68bc1ab527433da61a0a27d14d3b140ae015 Mon Sep 17 00:00:00 2001
From: Jakob Gabriel <jakob.gabriel@fau.de>
Date: Mon, 14 Oct 2019 10:24:22 +0200
Subject: [PATCH] quantity.Discrete: changed constructor, such that init with
 empty i.e. quantity.Discrete([]) works

---
 +quantity/Discrete.m | 43 ++++++++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/+quantity/Discrete.m b/+quantity/Discrete.m
index 050802b..667b645 100644
--- a/+quantity/Discrete.m
+++ b/+quantity/Discrete.m
@@ -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})
-- 
GitLab