www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgtabgradconstraint/setAxisVariables.m
function obj = setAxisVariables(obj, pAxisVariables, dim) %SETAXISVARIABLES Return the axes variables % % OBJ = SETAXISVARIABLES(OBJ, PAXISVARIABLES) sets the variables for all % axes to be the 1-by-NAXIS pointer array, PAXISVARIABLES. % % OBJ = SETAXISVARIABLES(OBJ, PAXISVARIABLE, DIM) sets the variable for % the DIM-th axis to be PAXISVARIABLE. % % See also CGTABGRADCONSTRAINT/GETAXISVARIABLES % Copyright 2006-2015 The MathWorks, Inc. % Get current object state oldAxisVariables = obj.pAxisVariables; oldAxisBreakpoints = obj.AxisBreakpoints; oldBounds = obj.Bounds; % Set the new axis variables if nargin < 3 obj.pAxisVariables = pAxisVariables(:)'; else obj.pAxisVariables(dim) = pAxisVariables; end % Number of axes NAXES = length(obj.pAxisVariables); % Recreate the breakpoints and gradient bounds for the axes obj.AxisBreakpoints = cell(1, NAXES); obj.Bounds = ones(NAXES, 3); if obj.IsVariable && ~isempty(obj.pItem) && isvalid(obj.pItem) % If a variable has been set, the initialise the maximum change to be 10% % of the variable's range obj.Bounds(:, [1 2]) = 0.1*diff(getrange(obj.pItem.info)); obj.Bounds(:,1) = -obj.Bounds(:,1); else % make bounds obj.Bounds(:, 1) = -10; obj.Bounds(:, 2) = 10; end for i = 1:NAXES thisRng = getrange(obj.pAxisVariables(i).info); thisBp = linspace(thisRng(1), thisRng(2), 10); obj.AxisBreakpoints{i} = thisBp; obj.Bounds(i, 3) = thisBp(2) - thisBp(1); end % Put back any breakpoints and bounds for axes that persist idxNew = findptrs(obj.pAxisVariables, oldAxisVariables); obj.AxisBreakpoints(idxNew > 0) = oldAxisBreakpoints(idxNew(idxNew > 0)); obj.Bounds(idxNew > 0, :) = oldBounds(idxNew(idxNew > 0), :); % Update the scaled axis breakpoints if ~isempty(obj.AxisBreakpoints) obj.ScaledAxisBreakpoints = pScaleAxisPoints(obj, obj.AxisBreakpoints); end % Reset the working store if in static mode if isStaticMode(obj) obj.WorkingStore.resetWorkingStore(); end