Commit 36b2d6e7 authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

Bugfix: Concatenation now works even if the first entry is not an quantity object

parent 55291ba5
......@@ -355,7 +355,7 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete
% X3 ...]' when any of X1, X2, X3, etc. is an object.
%
% See also HORZCAT, CAT.
c = a.cat(2, varargin{:});
c = cat(2, a, varargin{:});
end
function c = vertcat(a, varargin)
%VERTCAT Vertical concatenation.
......@@ -384,9 +384,9 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete
% X2; X3; ...]' when any of X1, X2, X3, etc. is an object.
%
% See also HORZCAT, CAT.
c = a.cat(1, varargin{:});
c = cat(1, a, varargin{:});
end
function c = cat(a, dim, varargin)
function c = cat(dim, a, varargin)
%CAT Concatenate arrays.
% CAT(DIM,A,B) concatenates the arrays of objects A and B
% from the class quantity.Discrete along the dimension DIM.
......@@ -418,27 +418,36 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete
if nargin == 1
objCell = {a};
else
objCell = [{a}, varargin(:)'];
for k = 1:numel(varargin)
% this function has the very special thing that it a does
% not have to be an quantity.Discrete object. So it has to
% be checked which of the input arguments is an
% quantity.Discrete object. This is considered to be give
% the basic values for the initialization of new
% quantity.Discrete values
isAquantityDiscrete = cellfun(@(o) isa(o, 'quantity.Discrete'), objCell);
objIdx = find(isAquantityDiscrete, 1);
obj = objCell{objIdx};
for k = 1:numel(objCell)
if isa(varargin{k}, 'quantity.Discrete')
o = varargin{k};
if isa(objCell{k}, 'quantity.Discrete')
o = objCell{k};
else
value = varargin{k};
value = objCell{k};
for l = 1:numel(value)
M(:,l) = repmat(value(l), prod(a(1).gridSize), 1);
M(:,l) = repmat(value(l), prod(obj(1).gridSize), 1);
end
M = reshape(M, [a(1).gridSize, size(value)]);
M = reshape(M, [obj(1).gridSize, size(value)]);
o = quantity.Discrete( M, ...
'gridName', a(1).gridName, ...
'grid', a(1).grid);
'gridName', obj(1).gridName, ...
'grid', obj(1).grid);
end
objArgin{k} = o;
objCell{k} = o;
end
objCell = [{a}, objArgin(:)'];
end
[fineGrid, fineGridName] = getFinestGrid(objCell{:});
for it = 1 : (numel(varargin) + 1) % +1 because the first entry is a
......
......@@ -203,7 +203,7 @@ classdef Symbolic < quantity.Function
%% mathematical operations
methods (Access = public)
function c = cat(a, dim, varargin)
function c = cat(dim, a, varargin)
%CAT Concatenate arrays.
% CAT(DIM,A,B) concatenates the arrays of objects A and B
% from the class quantity.Discrete along the dimension DIM.
......@@ -235,20 +235,30 @@ classdef Symbolic < quantity.Function
if nargin == 1
objArgin = {a};
else
% this function has the very special thing that it a does
% not have to be an quantity.Discrete object. So it has to
% be checked which of the input arguments is an
% quantity.Discrete object. This is considered to be give
% the basic values for the initialization of new
% quantity.Discrete values
objCell = [{a}, varargin(:)'];
isAquantityDiscrete = cellfun(@(o) isa(o, 'quantity.Discrete'), objCell);
objIdx = find(isAquantityDiscrete, 1);
obj = objCell{objIdx};
for k = 1:numel(varargin)
for k = 1:numel(objCell)
if isa(varargin{k}, 'quantity.Symbolic')
o = varargin{k};
elseif isa(varargin{k}, 'double') || isa(varargin{k}, 'sym')
o = quantity.Symbolic( varargin{k}, ...
'variable', a(1).variable, ...
'grid', a(1).grid);
if isa(objCell{k}, 'quantity.Symbolic')
o = objCell{k};
elseif isa(objCell{k}, 'double') || isa(objCell{k}, 'sym')
o = quantity.Symbolic( objCell{k}, ...
'variable', obj(1).variable, ...
'grid', obj(1).grid);
end
objArgin{k} = o;
objCell{k} = o;
end
end
c = cat@quantity.Discrete(a, dim, objArgin{:});
c = cat@quantity.Discrete(dim, objCell{:});
end
function solution = subs(obj, gridName, values)
......
......@@ -38,6 +38,9 @@ testCase.verifyEqual(F(2).valueSymbolic, sym(0))
F = [f1, sym(zeros(1, 10))];
testCase.verifyEqual([F(2:end).valueSymbolic], sym(zeros(1,10)))
%
F = [0, f1];
testCase.verifyEqual(F(1).valueSymbolic, sym(0))
end
function testExp(testCase)
......
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