## 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{ytick_values} =} yticks ## @deftypefnx {} {@var{ytick_mode} =} yticks (@var{'mode'}) ## @deftypefnx {} yticks (@var{'ytick_values'}) ## @deftypefnx {} yticks (@var{'ytickmode'}) ## @deftypefnx {} yticks (@var{hax}, @dots{}) ## Query or set the properties related to tick values on the y-axis of the ## current axis. ## ## When @code{yticks} is called without argument, @code{yticks} returns the ## current locations as specified in the @var{ytick} axis property. These values ## can be changed by calling @code{yticks} with a vector of tick values. Note: ## ascending order is not required. ## ## When called with argument @var{'mode'}, @code{yticks} returns the current ## value of the axis property @var{'ytickmode'}, which should return either ## @var{'auto'} or @var{'manual'}. This property can be changed by calling ## @code{yticks} with either @var{'auto'} or @var{'manual'} Note: changing the ## @var{ytick_values} will also set the property @var{'ytickmode'} 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{yticks} to set a property value ## will result in an error. ## ## @seealso{yticklabels, xticks, zticks, rticks, thetaticks, get, set} ## @end deftypefn ## Author: Nicholas Jankowski ## Created: 2017-08-24 function [retval] = yticks (varargin) #identify and set input values, shortcut simple cases switch nargin case 0 retval = get (gca , 'ytick'); #will error if no ytick 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, 'ytick'); elseif ischar(option) option = tolower(option); switch option case 'mode' retval = get (axis_to_use, 'ytickmode'); case {'auto','manual'} if (nargout > 0) error(['too many output arguments requested for option "', option, '"']) else set(axis_to_use, 'ytickmode', 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, 'ytick', option); endif else print_usage; endif endfunction ## Test input validation %!test %! hf = figure ("visible", "off"); %! unwind_protect %! set (gca, "ytickmode", "auto"); %! hax = gca; %! vals1 = yticks; %! assert (yticks (hax), vals1); %! mode1 = yticks ("mode"); %! assert (yticks (hax, "mode"), mode1); %! yticks (hax, "manual"); %! assert (yticks (hax, "mode"), "manual"); %! yticks (hax, "auto"); %! assert (yticks (hax, "mode"), "auto"); %! yticks (hax, [1 2 3 4]); %! assert (yticks (hax), [1 2 3 4]); %! assert (yticks (hax, "mode"), "manual"); %! unwind_protect_cleanup %! close (hf); %! end_unwind_protect