Commit 7014c89a authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

Make the changeGrid function behave like a call-by-value function

parent 14bab8de
......@@ -282,8 +282,10 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete
% that quantity has same grid and gridName as quantity a
% as well.
if isempty(a)
referenceGridName = '';
referenceGrid = {};
if nargin > 1
varargin{1}.assertSameGrid(varargin{2:end});
end
return;
else
referenceGridName = a(1).gridName;
referenceGrid= a(1).grid;
......@@ -315,9 +317,13 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete
% gridSize for each iteratively.
if isempty(a)
referenceGridName = '';
referenceGrid = {};
referenceGridSize = [];
if nargin > 1
[referenceGrid, referenceGridName] = varargin{1}.getFinestGrid(varargin{2:end});
else
referenceGrid = {};
referenceGridName = '';
end
return;
else
referenceGridName = a(1).gridName;
referenceGrid = a(1).grid;
......@@ -483,9 +489,13 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete
value = objCell{k};
for l = 1:numel(value)
M(:,l) = repmat(value(l), prod(obj(1).gridSize), 1);
end
if isempty(value)
M = zeros([prod(obj(1).gridSize), size(value(l))]);
end
M = reshape(M, [obj(1).gridSize, size(value)]);
o = quantity.Discrete( M, ...
'size', size(value), ...
'gridName', obj(1).gridName, ...
'grid', obj(1).grid);
end
......@@ -952,7 +962,7 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete
s = struct(obj);
end
function obj = changeGrid(obj, gridNew, gridNameNew)
function newObj = changeGrid(obj, gridNew, gridNameNew)
% change the grid of the obj quantity. The order of grid and
% gridName in the obj properties remains unchanged, only the
% data points are exchanged.
......@@ -968,11 +978,12 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete
end
assert(isequal(myGridName(:), obj(1).gridName(:)), 'rearranging grids failed');
newObj = obj.copy();
for it = 1 : numel(obj)
obj(it).valueDiscrete = obj(it).on(myGrid);
newObj(it).valueDiscrete = obj(it).on(myGrid);
end
[obj.derivatives] = deal({});
[obj.grid] = deal(myGrid);
[newObj.derivatives] = deal({});
[newObj.grid] = deal(myGrid);
end
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