Home > marsbar > @maroi > private > my_classdata.m

my_classdata

PURPOSE ^

my_classdata method - sets/gets class data

SYNOPSIS ^

function cdata = my_classdata(fieldname, value)

DESCRIPTION ^

 my_classdata method - sets/gets class data
 maroi class data is implemented with a persistent variable
 CLASSDATA  This is a structure containing fields

 spacebase  - space in which to do ROI combination 
 fileend    - filename end with extension for ROI files
 def_binthresh - default roithresh for binarize ROIs
 def_wtthresh  - default roithresh for non-binarize ROIs

 Field values can be returned with the call
    maroi('classdata') - which returns the whole structure
 or maroi('classdata', fieldname) - which returns field data

 Field values can be set with the call
 maroi('classdata', fieldname, value) OR
 maroi('classdata', struct) where struct contains fields matching those
 in CLASSDATA

 The same functionality results from 
 classdata(maroi_obj, fieldname) etc.

 Matthew Brett 1/8/01 (MRD+)

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function cdata = my_classdata(fieldname, value)
0002 % my_classdata method - sets/gets class data
0003 % maroi class data is implemented with a persistent variable
0004 % CLASSDATA  This is a structure containing fields
0005 %
0006 % spacebase  - space in which to do ROI combination
0007 % fileend    - filename end with extension for ROI files
0008 % def_binthresh - default roithresh for binarize ROIs
0009 % def_wtthresh  - default roithresh for non-binarize ROIs
0010 %
0011 % Field values can be returned with the call
0012 %    maroi('classdata') - which returns the whole structure
0013 % or maroi('classdata', fieldname) - which returns field data
0014 %
0015 % Field values can be set with the call
0016 % maroi('classdata', fieldname, value) OR
0017 % maroi('classdata', struct) where struct contains fields matching those
0018 % in CLASSDATA
0019 %
0020 % The same functionality results from
0021 % classdata(maroi_obj, fieldname) etc.
0022 %
0023 % Matthew Brett 1/8/01 (MRD+)
0024 %
0025 % $Id$
0026 
0027 persistent CLASSDATA
0028 if isempty(CLASSDATA)
0029   % default space is that of the SPM templates
0030   t1mat = [2     0     0   -92; ...
0031        0     2     0  -128; ... 
0032        0     0     2   -74; ...
0033        0     0     0     1];
0034   CLASSDATA = struct(...
0035       'spacebase', mars_space([91 109 91],  t1mat), ...
0036       'fileend','_roi.mat',...
0037       'def_hold', 1,...
0038       'def_binthresh', 0.5,...
0039       'def_wtthresh', eps);
0040 
0041 end
0042 
0043 if nargin < 1 % simple classdata call
0044   cdata = CLASSDATA;
0045   return
0046 end
0047 if nargin < 2 && ~isstruct(fieldname) % fieldname get call
0048   if isfield(CLASSDATA, fieldname) 
0049     cdata = getfield(CLASSDATA,fieldname);
0050   else 
0051     cdata = []; 
0052   end
0053   return
0054 end
0055 
0056 % some sort of set call
0057 if ~isstruct(fieldname) 
0058   fieldname = struct(struct(fieldname, value));
0059 end
0060 for field = fieldnames(fieldname)
0061   if isfield(CLASSDATA, field{1})
0062     CLASSDATA = setfield(CLASSDATA, field{1},...
0063                     getfield(fieldname, field{1}));
0064   end
0065 end
0066 cdata = CLASSDATA;

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