## Copyright (C) 2017 Nicholas Jankowski ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program. If not, see . ## -*- texinfo -*- ## @deftypefn {} {@var{xtick_values} =} xticks ## @deftypefnx {} {@var{xtick_mode} =} xticks (@var{'mode'}) ## @deftypefnx {} xticks (@var{'xtick_values'}) ## @deftypefnx {} xticks (@var{'xtickmode'}) ## @deftypefnx {} xticks (@var{hax}, @dots{}) ## Query or set the properties related to tick values on the x-axis of the ## current axis. ## ## When @code{xticks} is called without argument, @code{xticks} returns the ## current locations as specified in the @var{xtick} axis property. These values ## can be changed by calling @code{xticks} with a vector of tick values. Note: ## ascending order is not required. ## ## When called with argument @var{'mode'}, @code{xticks} returns the current ## value of the axis property @var{'xtickmode'}, which should return either ## @var{'auto'} or @var{'manual'}. This property can be changed by calling ## @code{xticks} with either @var{'auto'} or @var{'manual'} Note: changing the ## @var{xtick_values} will also set the property @var{'xtickmode'} to ## @var{'manual'}. ## ## If the first argument @var{hax} is an axes handle, then operate on ## this axis rather than the current axes returned by @code{gca}. ## ## Requesting a return value when calling @code{xticks} to set a property value ## will result in an error. ## ## @seealso{xticklabels, yticks, zticks, rticks, thetaticks, get, set} ## @end deftypefn ## Author: Nicholas Jankowski ## Created: 2017-08-24 function [retval] = xticks (varargin) #identify and set input values, shortcut simple cases switch nargin case 0 retval = get (gca , 'xtick'); #will error if no xtick exists. return; case 1 axis_to_use = gca; option = varargin{1}; case 2 #if 2 inputs, first must specify an axis handle. if (~ishandle (varargin{1}) || ishandle (varargin{2})) print_usage; else axis_to_use = varargin{1}; option = varargin{2}; endif otherwise print_usage; endswitch # axis and option are set, perform requested actions based on 'option' class if ishandle(option) retval = get (option, 'xtick'); elseif ischar(option) option = tolower(option); switch option case 'mode' retval = get (axis_to_use, 'xtickmode'); case {'auto','manual'} if (nargout > 0) error(['too many output arguments requested for option "', option, '"']) else set(axis_to_use, 'xtickmode', option); endif otherwise error(['invalid option "', option, '"']) endswitch elseif (isnumeric(option)) if (nargout > 0) error('too many output arguments requested') else ## NOTE: Matlab errors if tick points are not in ascending order. Octave ## permits out of order tick points, so error is not produced. set(axis_to_use, 'xtick', option); endif else print_usage; endif endfunction ## Test input validation %!test %! hf = figure ("visible", "off"); %! unwind_protect %! set (gca, "xtickmode", "auto"); %! hax = gca; %! vals1 = xticks; %! assert (xticks (hax), vals1); %! mode1 = xticks ("mode"); %! assert (xticks (hax, "mode"), mode1); %! xticks (hax, "manual"); %! assert (xticks (hax, "mode"), "manual"); %! xticks (hax, "auto"); %! assert (xticks (hax, "mode"), "auto"); %! xticks (hax, [1 2 3 4]); %! assert (xticks (hax), [1 2 3 4]); %! assert (xticks (hax, "mode"), "manual"); %! unwind_protect_cleanup %! close (hf); %! end_unwind_protect