mc%% Make test AOsnsecs = 10000;fs = 10;pl = plist('nsecs', nsecs, 'fs', fs, 'tsfcn', 'sin(2*pi*7.433*t) + randn(size(t))');a1 = ao(pl);a1.setName('a1');a1.setYunits('m');% This should output Niunits1 = unit('m');ounits1 = unit('V');iunits2 = unit('V');ounits2 = unit('N');lp = miir(plist('type', 'lowpass', 'fs', fs, 'fc', 0.1, 'order', 5,'iunits', iunits1, 'ounits', ounits1));hp = miir(plist('type', 'highpass', 'fs', fs, 'fc', 1, 'order', 2,'iunits', iunits2, 'ounits', ounits2));a1f = filter(a1, [lp hp], plist('bank', 'serial'));%% Simplifyb = a1f.simplifyYunits()%% Units with prefixesa = ao(1:10);a.setYunits('mm m^-1')a.simplifyYunits%% Units with prefixesa = ao(1:10);a.setYunits('mm m Hz um^-2')a.simplifyYunits(plist('prefixes', true))%% More tests on prefixesN = 8;test = true(N,1);% Case 1jj = 1;% A unit is canceled out but there is a remaining prefix AND a remaining unit.% Example: 'fN mN^-1 Hz'a = ao([1:10]',[2:2:20]',plist('xunits','s'));a.setYunits('fN mN^-1 Hz');% The unit Newton will be canceled out and the remaining prefix (here 'p') will be added to the Hzb = simplifyYunits(a, plist('prefixes', true));c = simplifyYunits(a, plist('prefixes', false));% Result: 'pHz'if ne(b.yunits, unit('Hz')) || ne(c.yunits, unit('pHz')) test(jj) = false;end% Case 2jj = 2;% A unit is canceled out but there is a remaining prefix AND NO remaining unit.% Example: 'fN mN^-1'a = ao([1:10]',[2:2:20]',plist('xunits','s'));a.setYunits('fN mN^-1');% In this case it is not possible to keep the remaining prefix% --> Don't simplify the unit (it is only possible if we compute the prefix to the values)b = simplifyYunits(a, plist('prefixes', true));c = simplifyYunits(a, plist('prefixes', false));% Result: 'fN mN^-1'if ne(b.yunits, unit('')) || ne(c.yunits, unit('fN mN^-1')) test(jj) = false;end% Case 3jj = 3;% The 'normal' case% Example: 'fN m^-2 mN^-2 Hz mm'a = ao([1:10]',[2:2:20]',plist('xunits','s'));a.setYunits('fN m^-2 mN^-2 Hz mm');b = simplifyYunits(a, plist('prefixes', true));c = simplifyYunits(a, plist('prefixes', false));% Result: 'GN^-1 km^-1 Hz'if ne(b.yunits, unit('N^-1 m^-1 Hz')) || ne(c.yunits, unit('GN^-1 km^-1 Hz')) test(jj) = false;end% Case 4jj = 4;% Power% Example: ('mm')^2a = ao([1:10]',[2:2:20]',plist('xunits','s'));a.setYunits('mm');b = simplifyYunits(a.^2, plist('prefixes', true));c = simplifyYunits(a.^2, plist('prefixes', false));% Result: 'mm^2'if ne(b.yunits, unit('m^2')) || ne(c.yunits, unit('mm^2')) test(jj) = false;end% Case 5jj = 5;% Powern = utils.math.randelement([-4:-1 1:4],1);% Example: ('mm^-1 nm^-1')^na = ao([1:10]',[2:2:20]',plist('xunits','s'));a.setYunits('mm^-1 nm^-1');b = simplifyYunits(a.^n, plist('prefixes', true));c = simplifyYunits(a.^n, plist('prefixes', false));% Result: 'um^-n'if ne(b.yunits, unit(['m^' num2str(n*-2)])) || ne(c.yunits, unit(['um^' num2str(n*-2)])) test(jj) = false;end% Case 6jj = 6;% A unit is canceled out but there is a remaining prefix AND a% remaining unit.% Example: ('mm um ks^-1 s')a = ao([1:10]',[2:2:20]',plist('xunits','s'));a.setYunits('mm um ks^-1 s');b = simplifyYunits(a, plist('prefixes', true))c = simplifyYunits(a, plist('prefixes', false))% Result: 'um^2'if ne(b.yunits, unit('m^2')) || ne(c.yunits, unit('um^2')) test(jj) = false;end% Case 7jj = 7;% A unit is canceled out but there is a remaining prefix AND a% remaining unit.% Example: ('mm um ks^-1 s')a = ao([1:10]',[2:2:20]',plist('xunits','s'));a.setYunits('mm um ks^-1 s');b = simplifyYunits(sqrt(a), plist('prefixes', true))c = simplifyYunits(sqrt(a), plist('prefixes', false))% Result: 'um^2'if ne(b.yunits, unit('m')) || ne(c.yunits, unit('um')) test(jj) = false;end% Case 8jj = 8;% Sqrt of Powern = utils.math.randelement([-4:-2 2:4],1);% Example: ('mm^-1 nm^-1')^2na = ao([1:10]',[2:2:20]',plist('xunits','s'));a.setYunits('mm^-1 nm^-1');b = simplifyYunits(sqrt(a.^(2*n)), plist('prefixes', true))c = simplifyYunits(sqrt(a.^(2*n)), plist('prefixes', false))% Result: 'um^-n'if ne(b.yunits, unit(['m^' num2str(n*-2)])) || ne(c.yunits, unit(['um^' num2str(n*-2)])) test(jj) = false;end