Commit 7ded3f9a authored by Jakob Gabriel's avatar Jakob Gabriel
Browse files

quantity.Domain.replace

parent f3be9c05
......@@ -250,6 +250,18 @@ classdef (InferiorClasses = {?quantity.EquidistantDomain}) Domain < ...
rest = obj(~logicalIdxToBeRemoved);
end % remove()
function obj = replace(obj, toBeReplaced)
% REPLACE replaced a domain with another domain.
%
% obj = replace(obj, toBeReplaced) replaces the element of the obj with the same name
% as the toBeReplaced domain with the new domain toBeRelaced.
thisIdx = obj.index(toBeReplaced);
if thisIdx > 0
obj(thisIdx) = toBeReplaced;
end
end % replace()
function [idx, log] = index( obj, searchName, position)
%% GRIDINDEX returns the index of the grid
% [idx, log] = index(obj, names) searches in the name
......
......@@ -2,6 +2,26 @@ function [tests] = testDomain()
tests = functiontests(localfunctions);
end
function testReplace(tc)
z = linspace(0, pi, 3);
a = quantity.Domain("a", z);
b = quantity.Domain("b", z);
c = quantity.Domain("c", z);
d = [a b c];
d = d.replace(quantity.Domain("b", linspace(0, 1, 2)));
tc.verifyEqual([d.name], ["a"; "b"; "c"].');
tc.verifyEqual(d(1).grid, linspace(0, pi, 3).');
tc.verifyEqual(d(3).grid, linspace(0, pi, 3).');
tc.verifyEqual(d(2).grid, linspace(0, 1, 2).');
d = d.replace(quantity.Domain("e", linspace(2, 3, 4)));
tc.verifyEqual([d.name], ["a"; "b"; "c"].');
tc.verifyEqual(d(1).grid, linspace(0, pi, 3).');
tc.verifyEqual(d(3).grid, linspace(0, pi, 3).');
tc.verifyEqual(d(2).grid, linspace(0, 1, 2).');
end % testReplace
function setupOnce(tc)
z = linspace(0, pi, 3);
......
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