Home > marsbar > @maroi_matrix > domaths.m

domaths

PURPOSE ^

helper function to do maths on matrix object

SYNOPSIS ^

function o = domaths(func, dat1, dat2)

DESCRIPTION ^

 helper function to do maths on matrix object
 Binary operations (& | ~ xor etc) return binarize type objects
 Other operations return not-binarize type objects
 ROI reslicing thresholds are set from defaults

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function o = domaths(func, dat1, dat2)
0002 % helper function to do maths on matrix object
0003 % Binary operations (& | ~ xor etc) return binarize type objects
0004 % Other operations return not-binarize type objects
0005 % ROI reslicing thresholds are set from defaults
0006 %
0007 % $Id$
0008   
0009 if nargin < 2
0010   error('Need function and object');
0011 end
0012 if nargin < 3
0013    dat2 = [];
0014 end
0015 d1 = describething(dat1);
0016 d2 = describething(dat2);
0017 
0018 if isa(dat1, 'maroi')
0019   o = dat1; dat1 = dat1.dat;
0020 else % second must be an object
0021   o = dat2; 
0022 end
0023 if isa(dat2, 'maroi')
0024   dat2 = dat2.dat;
0025 end
0026 
0027 if nargin < 3 % no second object
0028   d = sprintf('%s(%s)', func, d1);
0029 else % there is a second object / thing
0030   d = sprintf('%s(%s, %s)', func, d1, d2);
0031 end
0032 
0033 switch func
0034   case 'and'
0035    o.dat = dat1 & dat2;
0036   case 'or'
0037    o.dat = dat1 | dat2;
0038   case 'not'
0039    o.dat = ~dat1;
0040   case 'xor'
0041    o.dat = xor(dat1, dat2);
0042   case 'plus'
0043    o.dat = dat1 + dat2;
0044   case 'minus'
0045    o.dat = dat1 - dat2;
0046   case 'times'
0047    o.dat = dat1 .* dat2;
0048   case 'divide'
0049    o.dat = dat1 ./ dat2;
0050   case 'lt'
0051    o.dat = dat1 < dat2;
0052   case 'gt'
0053    o.dat = dat1 > dat2;
0054   case 'le'
0055    o.dat = dat1 <= dat2;
0056   case 'ge'
0057    o.dat = dat1 >= dat2;
0058   case 'eq'
0059    o.dat = dat1 == dat2;
0060   case 'ne'
0061    o.dat = dat1 ~= dat2;
0062  otherwise
0063   error(['Function ' func ' not yet defined']);
0064 end
0065 
0066 % convert from logical to double if necessary
0067 o.dat = double(o.dat);
0068 
0069 binf = ismember(func, {...
0070     'and',...
0071     'or',...
0072     'not',...
0073     'xor',...
0074     'lt',...
0075     'gt',...
0076     'le',...
0077     'ge',...
0078     'eq',...
0079     'ne'});
0080 
0081 o = binarize(o, binf);
0082 if binf
0083   o = roithresh(o, maroi('classdata', 'def_binthresh'));
0084 else
0085   o = roithresh(o, maroi('classdata', 'def_wtthresh'));
0086 end
0087 o = descrip(o, d);
0088 o = source(o, '');
0089 
0090 function d = describething(o)
0091 if isa(o, 'maroi')
0092   d = descrip(o);
0093 elseif isnumeric(o)
0094   if prod(size(o)) == 1 % scalar
0095     d = num2str(o);
0096   else
0097     d = '[matrix]';
0098   end    
0099 else
0100   d = '[non numeric input]';
0101 end

Generated on Wed 11-May-2022 16:26:09 by m2html © 2003-2019