Commit 944a0b52 authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

New function to replace a grid by a new grid

parent b61bccf0
......@@ -1410,7 +1410,54 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
for it = 1 : numel(obj)
newObj(it).valueDiscrete = obj(it).on(newDomain);
end
end
end % changeGrid
function newObj = replaceGrid(obj, myNewDomain, optArgs)
% CHANGEGRID change the grid of the quantity.
% newObj = REPLACEGRID(obj, MYNEWDOMAIN, "gridName", NEWGRIDNAME)
% replace the grid of the obj quantity. The order of grid and
% gridName in the obj properties remains unchanged, only the
% grid points are exchanged.
%
% TODO:
% newObj = REPLACEGRID(obj, domain) changes the domain of the
% object specified by the name of DOMAIN into DOMAIN.
%
% newObj = REPLACEGRID(obj, domain, 'gridName', NEWNAME) changes the domain of the
% object specified by NEWNAME into DOMAIN.
arguments
obj
myNewDomain quantity.Domain
optArgs.gridName = [myNewDomain.name];
end
if isempty(obj)
newObj = obj.copy();
return;
end
assert( intersect(obj(1).gridName, optArgs.gridName) == optArgs.gridName );
if obj(1).isConstant
error("Not yet implemented")
else
gridIndexNew = obj(1).domain.gridIndex(optArgs.gridName);
% initialization of the newDomain array as quantity.Domain
% array. This is required in order to handle also
% quantity.EquidistantDomains:
newDomain(1:obj(1).nargin) = quantity.Domain();
newDomain(:) = obj(1).domain;
for it = 1 : length(gridIndexNew)
newDomain(gridIndexNew(it)) = ...
quantity.Domain(myNewDomain(it).name, myNewDomain(it).grid);
end
end
newObj = obj.copy();
[newObj.domain] = deal(newDomain);
end % replaceGrid
end
%% math
......
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