Home > bioelectromagnetism > eeg_contour_levels.m

eeg_contour_levels

PURPOSE ^

eeg_contour_levels - Defines contour levels relative to zero.

SYNOPSIS ^

function [Clevels] = eeg_contour_levels( step, data )

DESCRIPTION ^

 eeg_contour_levels - Defines contour levels relative to zero.

 Useage: [Clevels] = eeg_contour_levels( step, data )

           step     - the step size
           data     - array of values
           Clevels  - array of values at steps

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Clevels] = eeg_contour_levels( step, data )
0002 
0003 % eeg_contour_levels - Defines contour levels relative to zero.
0004 %
0005 % Useage: [Clevels] = eeg_contour_levels( step, data )
0006 %
0007 %           step     - the step size
0008 %           data     - array of values
0009 %           Clevels  - array of values at steps
0010 %
0011 
0012 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:33 $
0013 
0014 % Licence:  GNU GPL, no implied or express warranties
0015 % History:  Created 07/2001, Darren.Weber_at_radiology.ucsf.edu
0016 %           - developed under IDL and recoded for matlab
0017 %
0018 % BUG:      - may need to generate one more
0019 %             negative contour level because matlab doesn't
0020 %             fill the min contour level.
0021 %           - 04/2002, Darren.Weber
0022 %             modified lines 28 to 45 to attempt a fix
0023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0024 
0025 Clevels = [];
0026 
0027 %Ensure step is a positive value
0028 step = abs(step);
0029 
0030 
0031 % Calculate min step range of voltage values
0032 minstep = 0;
0033 if min(data) < 0,
0034     while minstep - step > min(data),
0035         minstep = minstep - step;
0036     end
0037 else
0038     while minstep < min(data),
0039         minstep = minstep + step;
0040     end
0041 end
0042 
0043 % Calculate max step range of voltage values
0044 maxstep = 0;
0045 if max(data) > 0
0046     while maxstep + step < max(data),
0047         maxstep = maxstep + step;
0048     end
0049 else
0050     while maxstep > max(data),
0051         maxstep = maxstep - step;
0052     end
0053 end
0054 
0055 
0056 
0057 % Check for unusual conditions
0058 if (minstep > maxstep),
0059     fprintf('...eeg_contour_levels, minstep > maxstep, revise step.\n');
0060     if minstep > min(data) & minstep < max(data),
0061         Clevels = minstep;
0062     end
0063     if maxstep > min(data) & maxstep < max(data),
0064         Clevels = maxstep;
0065     end
0066     return
0067 end
0068 if and(maxstep == 0, minstep == 0),
0069     fprintf('...eeg_contour_levels, step too large for min/max of data.\n');
0070     return
0071 end
0072 
0073 
0074 
0075 % Define Clevels according to min/max step relative to zero
0076 
0077 if and(minstep < 0.0, maxstep > 0.0)
0078     
0079     % Define number of negative levels, given step and range
0080     nlevels = round( ( 0 - minstep ) / step );
0081     % Define column (Narray) to hold (nlevels) from -step to minstep
0082     for a = 0:(nlevels -1), Narray(1,a+1) = (-1 * step) - (a * step); end
0083 
0084     % Define number of positive levels, given step and range
0085     plevels = round( maxstep / step );
0086     % Define column (Parray) to hold (plevels) from zero to maxstep
0087     for a = 0:plevels, Parray(1,a+1) = step * a; end
0088 
0089     Clevels = [fliplr(Narray), Parray];
0090     return
0091 end
0092 
0093 if and(minstep < 0.0, maxstep <= 0.0)
0094 
0095     % Define number of negative levels, given step and range
0096     nlevels = round( ( maxstep - minstep ) / step );
0097     % Define (Narray) to hold nlevels from maxstep to minstep
0098     % (max[data] may not be in Narray).
0099     for a = 0:nlevels, Narray(1,a+1) = maxstep - (step * a); end
0100 
0101     Clevels = fliplr(Narray);
0102     return
0103 end
0104 
0105 if and(minstep >= 0.0, maxstep > 0.0)
0106 
0107     % Define number of positive levels, given step and range
0108     plevels = round( ( maxstep - minstep ) / step );
0109     % Define (Parray) to hold (plevels) from minstep to maxstep,
0110     % (min[data] may not be in Parray).
0111     for a = 0:plevels, Parray(1,a+1) = minstep + (step * a); end
0112 
0113     Clevels = Parray;
0114     return
0115 end

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003