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