Commit 3eda586f authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

added split function to quantity.Domain

parent e0d4c215
......@@ -68,6 +68,29 @@ classdef (InferiorClasses = {?quantity.EquidistantDomain}) Domain < ...
methods (Access = public)
function d = split(obj, splittingPoints)
idx(1) = 1;
for k = 1:numel(splittingPoints)
[val, idx(k+1)] = min( abs( (obj.grid - splittingPoints(k)) ));
delta = abs( obj.grid(idx(k+1)) - splittingPoints(k));
if delta > 1e-3
warning('The deviation of the grid from desired splitting point %d is %d\n', splittingPoints(k), delta);
end
d(k) = quantity.Domain(obj.name, obj.grid(idx(k):idx(k+1)));
end
d(k+1) = quantity.Domain(obj.name, obj.grid(idx(k+1):end));
end
function [i, logIdx] = contains(obj, d)
logIdx = false(obj.n,1);
......
......@@ -18,6 +18,25 @@ tc.TestData.d = d;
end
function testSplit(testCase)
a = quantity.Domain('a', -5:15 );
b = a.split([-1, 0, 4]);
testCase.verifyEqual(b(1).grid', -5:-1)
testCase.verifyEqual(b(2).grid', -1:0)
testCase.verifyEqual(b(3).grid', 0:4)
testCase.verifyEqual(b(4).grid', 4:15)
c = a.split([0.1, 2.6]);
testCase.verifyEqual(c(1).grid', -5:0)
testCase.verifyEqual(c(2).grid', 0:3)
testCase.verifyEqual(c(3).grid', 3:15)
end
function testContains(testCase)
a = quantity.Domain('a', 0:10);
......@@ -253,4 +272,5 @@ 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