line source
mc
%% Some AOs
c1 = ao(1); c1.setName;
c2 = ao(2); c2.setName;
c3 = ao(3); c3.setName;
c4 = ao(randn(3,3)); c4.setName;
c5 = ao(randn(3,3)); c5.setName;
c6 = ao(randn(3,1)); c6.setName;
c7 = ao(randn(1,3)); c7.setName;
t1 = ao(plist('tsfcn', 't', 'fs', 10, 'nsecs', 10)); t1.setName;
t2 = ao(plist('tsfcn', 'sqrt(t)', 'fs', 10, 'nsecs', 10)); t2.setName;
t3 = ao(plist('tsfcn', 't.^2', 'fs', 10, 'nsecs', 10)); t3.setName;
f1 = ao(plist('fsfcn', 'f', 'f', 'logspace(-4,1,100)')); f1.setName;
f2 = ao(plist('fsfcn', '1./f', 'f', 'logspace(-4,1,100)')); f2.setName;
f3 = ao(plist('fsfcn', 'sqrt(f)', 'f', 'logspace(-4,1,100)')); f3.setName;
x1 = ao(plist('xyfcn', 'x', 'x', '1:100')); x1.setName;
x2 = ao(plist('xyfcn', '1./x', 'x', '1:100')); x2.setName;
x3 = ao(plist('xyfcn', 'sqrt(x)', 'x', '1:100')); x3.setName;
%% Rule 1
%---------- CDATA
% cdata + cdata
r1 = minus(c1,c3);
% cdata + tsdata
r2 = minus(c1,t1);
% cdata + fsdata
r3 = minus(c1,f1);
% cdata + xydata
r4 = minus(c1,x1);
%---------- TSDATA
% tsdata + tsdata
r5 = minus(t1, t2);
% tsdata + fsdata
try
r6 = minus(t1, f2);
error('Data types should be incompatible: booo!');
catch
lasterr
warning('Data types not compatible: fsdata+tsdata: hoorah!');
end
% tsdata + xydata
r7 = minus(t1, x2);
% tsdata + cdata
r8 = minus(t1, c2);
%---------- FSDATA
% fsdata + tsdata
try
r9 = minus(f1, t2);
error('Data types should be incompatible: booo!');
catch
lasterr
warning('Data types not compatible: fsdata+tsdata: hoorah!');
end
% fsdata + fsdata
r10 = minus(f1, f2);
% fsdata + xydata
r11 = minus(f1, x2);
% fsdata + cdata
r12 = minus(f1, c2);
%---------- XYDATA
% xydata + tsdata
r13 = minus(x1, t2);
% xydata + fsdata
r14 = minus(x1, f2);
% xydata + xydata
r15 = minus(x1, x2);
% xydata + cdata
r16 = minus(x1, c2);
%% Rule 2: vector + single
v = [t1 t2];
s = c2;
% one output
r1 = minus(v,s)
r2 = minus(s,v)
% multiple outputs
[r1 r2] = minus(v,s)
%% Rule 3: V_N + V_M
v1 = [t1 t2];
v2 = [c1 c2 c3];
try
r = minus(v1,v2);
error('Rule 3 should fail: booo!');
catch
lasterr
warning('Rule 3 fails: hoorah!');
end
%% Rule 4: V_N + U_N
v1 = [t1 t2 t3];
v2 = [x1 x2 x3];
r = minus(v1,v2);
[r1 r2 r3] = minus(v1,v2);
%% Rule 5: matrix + single
m = [t1 t2 t3; x1 x2 x3];
s = c2;
r1 = minus(m,s);
r2 = minus(s,m);
%% Rule 6: matrix + column vector
m = [t1 t2 t3; x1 x2 x3];
v = [c1; c2];
r1 = minus(m,v)
r2 = minus(v,m)
%% Rule 7: matrix + row vector
m = [t1 t2 t3; x1 x2 x3];
v = [c1 c2 c3];
r1 = minus(m,v)
r2 = minus(v,m)
%% Rule 8: M_NP + V_1Q (or V_Q1)
m = [t1 t2 t3; x1 x2 x3];
v = [c1 c2];
try
r = minus(m,v)
error('Rule 8 should fail: booo!');
catch
lasterr
warning('Rule 8 fails: hoorah!');
end
try
r = minus(v,m)
error('Rule 8 should fail: booo!');
catch
lasterr
warning('Rule 8 fails: hoorah!');
end
m = [t1 t2 t3; x1 x2 x3];
v = [c1; c2; c3];
try
r = minus(m,v)
error('Rule 8 should fail: booo!');
catch
lasterr
warning('Rule 8 fails: hoorah!');
end
try
r = minus(v,m)
error('Rule 8 should fail: booo!');
catch
lasterr
warning('Rule 8 fails: hoorah!');
end
%% Rule 9: M_NP + H_PQ
m = [t1 t2; x1 x2];
h = [c1 c2 c3; c1 c2 c3];
try
r = minus(m,h)
error('Rule 9 should fail: booo!');
catch
lasterr
warning('Rule 9 fails: hoorah!');
end
%% Rule 10: matrix + matrix
m = [t1 t2 t3; x1 x2 x3];
h = [c1 c2 c3; c1 c2 c3];
r = minus(m,h)
%% Rule 11: more than two inputs
m = [t1 t2 t3; x1 x2 x3];
v = [c1; c2];
r = minus(m,v, c3, v, m)
%% Check units
% empty + m = m
t1.setYunits('m');
t2.setYunits('');
r = minus(t1,t2)
% V + m = error
t2.setYunits('V');
try
r = minus(t1,t2)
error('This unit check should fail: booo!');
catch
lasterr
warning('The unit check failed: hoorah!');
end