Changeset 20132


Ignore:
Timestamp:
02/11/16 19:36:12 (9 years ago)
Author:
Eric.Larour
Message:

CHG: added getfieldvalues (specifically for the slm constructor).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/classes/pairoptions.m

    r19040 r20132  
    219219                        end
    220220                end % }}}
     221                function values = getfieldvalues(self,field,varargin), % {{{
     222                %GETOPTION - get the value of an option (if the option is repeated, return multiple values)
     223                %
     224                %   Usage:
     225                %      values=getfieldvalues(self,field,varargin)
     226                %
     227                %   Find all option values from a field. Default options
     228                %   can be given in input if the field does not exist
     229                %
     230                %   Examples:
     231                %      values=getfieldvalue(options,'caxis');
     232                %      values=getfieldvalue(options,'caxis',{[0 2],[3 4]});
     233
     234                        %some argument checking:
     235                        if nargin~=2 && nargin~=3,
     236                                help getfieldvalues
     237                                error('getfieldvalues error message: bad usage');
     238                        end
     239
     240                        if ~ischar(field),
     241                                error('getfieldvalues error message: field should be a string');
     242                        end
     243
     244                        %Recover options
     245                        pos=find(strcmpi(self.list(:,1),field));
     246                        if ~isempty(pos),
     247                                values={};
     248                                for i=1:length(pos),
     249                                        values{i}=self.list{pos(i),2};
     250                                        self.list{pos(i),3}=true;  % option used
     251                                end
     252                                return;
     253                        end
     254
     255                        %The option has not been found, output default if provided
     256                        if nargin==3,
     257                                values=varargin{1};
     258                        else
     259                                error(['error message: field ' field ' has not been provided by user (and no default value has been specified)'])
     260                        end
     261                end % }}}
    221262                function self = removefield(self,field,warn)% {{{
    222263                %REMOVEFIELD - delete a field in an option list
Note: See TracChangeset for help on using the changeset viewer.