function saturation_cb(blk,callback,uplimsrc,uplim,lowlimsrc,lowlim) % implements the callbacks for saturation block switch callback case 'init' init_cb(blk,uplimsrc,uplim,lowlimsrc,lowlim) case 'uplimsrc' uplimsrc_cb(blk) case 'lowlimsrc' lowlimsrc_cb(blk) otherwise disp('saturation_cb: callback not implemented') end % uplimsrc_cb Dialog Callback function uplimsrc_cb(blk) en = get_param(blk,'MaskEnables'); switch get_param(blk,'uplimsrc') case 'external' en{2} = 'off'; case 'internal' en{2} = 'on'; otherwise disp('Should never get here') end set_param(blk,'MaskEnables',en) % lowlimsrc_cb Dialog Callback function lowlimsrc_cb(blk) en = get_param(gcb,'MaskEnables'); switch get_param(gcb,'lowlimsrc') case 'external' en{4} = 'off'; case 'internal' en{4} = 'on'; otherwise disp('Should never get here') end set_param(gcb,'MaskEnables',en) % init_cb Mask Initialization function init_cb(blk,uplimsrc,uplim,lowlimsrc,lowlim) % Check for upper limit source switch uplimsrc case 'external' % Check for constant if strcmp(get_param([blk '/up'],'BlockType'),'Constant') replace([blk '/up'],'built-in/Inport'); end case 'internal' % Check for inport if strcmp(get_param([blk '/up'],'BlockType'),'Inport') replace([blk '/up'],'built-in/Constant') set_param([blk '/up'],'Value','uplim') end otherwise disp('Error: uplimsrc = ') disp(uplimsrc) end % Check for lower limit source switch lowlimsrc case 'external' % Check for constant if strcmp(get_param([blk '/lo'],'BlockType'),'Constant') replace([blk '/lo'],'built-in/Inport') end case 'internal' % Check for inport if strcmp(get_param([blk '/lo'],'BlockType'),'Inport') replace([blk,'/lo'],'built-in/Constant') set_param([blk '/lo'],'Value','lowlim') end otherwise disp('Error: lowlimsrc = ') disp(lowlimsrc) end % Renumber ports % when using external upper limit, set blk/up port to 1 n = 1; if strcmp(uplimsrc,'external') set_param([blk '/up'],'Port',num2str(n)) n = 2; % increase n end % set u port to n set_param([blk '/u'],'Port',num2str(n)) % when using external lower limit, set blk/lo port to n+1 if strcmp(lowlimsrc,'external') set_param([blk '/lo'],'Port',num2str(n+1)) end % Local replace function function replace(oldblock,newblock) pos = get_param(oldblock,'Position'); orient = get_param(oldblock,'Orientation'); delete_block(oldblock); add_block(newblock,oldblock,'Position',pos,... 'Orientation',orient);