[Index for tmp_for_tar/struct] [Return to Master Index]

fields

(tmp_for_tar/struct/fields.m)


Function Synopsis

f = fields(s,...)

Help text

        f = fields(s)

 if version >= 2.1.14 
        Returns the list of fieldnames in structure s. 
        Returns an empty list if s is not a struct. 
 else
        Returns a string array of fieldnames in structure s.
        Returns '' if s is not a struct. 

 Force the string behavior with :

        f = fields(s,'string')
        Returns a string array of fieldnames in structure s. 
        Returns '' if s is not a struct.  

 For m****b compatibility and flexibility. 

 See also cmpstruct, getfield, setfield, rmfield, isfield, isstruct,
 struct. 

 Last modified: January 2000



Listing of function file tmp_for_tar/struct/fields.m

##        f = fields(s)
## 
## if version >= 2.1.14 
##        Returns the list of fieldnames in structure s. 
##        Returns an empty list if s is not a struct. 
## else
##        Returns a string array of fieldnames in structure s.
##        Returns '' if s is not a struct. 
## 
## Force the string behavior with :
##
##        f = fields(s,'string')
##        Returns a string array of fieldnames in structure s. 
##        Returns '' if s is not a struct.  
##
## For m****b compatibility and flexibility. 
##
## See also cmpstruct, getfield, setfield, rmfield, isfield, isstruct,
## struct. 


## Author:        Etienne Grossmann  <etienne@isr.ist.utl.pt>
## Last modified: January 2000

function f = fields(s,...)

  opt = '' ;			# Check for option
  if --nargin , opt = va_arg() ; end

				# Check for octave version. Force to
				# string if version < 2.1.14
  vernum = str2num(split (OCTAVE_VERSION, '.')) ;
  if (vernum(1) < 2) || (vernum(1)==2 && vernum(2) < 1) ...
        || (all(vernum(1:2) == [2;1]) && vernum(3) < 14)
    opt = 'string' ;
  end

  if ! strcmp( opt, 'string' ),	# Default return type is list
    f = list() ;
    i = 1 ;
    for [val, key] = s ,
      f(i++) = key ;
    end
  else				# But on 2.0.14, return string
    f = ' ' ;
    for [val, key] = s ,
      f = [f;key] ;
    end
    f = f(2:size(f,1),:) ;
    ## f = struct_elements(s);
  end
endfunction



Produced by oct2html on Wed Aug 8 19:47:02 2001
Cross-Directory links are: ON