comparison scripts/general/structfun.m @ 11587:c792872f8942

all script files: untabify and strip trailing whitespace
author John W. Eaton <jwe@octave.org>
date Thu, 20 Jan 2011 17:35:29 -0500
parents fd0a3ac60b0e
children cefd568ea073
comparison
equal deleted inserted replaced
11586:12df7854fa7c 11587:c792872f8942
20 ## -*- texinfo -*- 20 ## -*- texinfo -*-
21 ## @deftypefn {Function File} {} structfun (@var{func}, @var{S}) 21 ## @deftypefn {Function File} {} structfun (@var{func}, @var{S})
22 ## @deftypefnx {Function File} {[@var{A}, @dots{}] =} structfun (@dots{}) 22 ## @deftypefnx {Function File} {[@var{A}, @dots{}] =} structfun (@dots{})
23 ## @deftypefnx {Function File} {} structfun (@dots{}, "ErrorHandler", @var{errfunc}) 23 ## @deftypefnx {Function File} {} structfun (@dots{}, "ErrorHandler", @var{errfunc})
24 ## @deftypefnx {Function File} {} structfun (@dots{}, "UniformOutput", @var{val}) 24 ## @deftypefnx {Function File} {} structfun (@dots{}, "UniformOutput", @var{val})
25 ## 25 ##
26 ## Evaluate the function named @var{name} on the fields of the structure 26 ## Evaluate the function named @var{name} on the fields of the structure
27 ## @var{S}. The fields of @var{S} are passed to the function @var{func} 27 ## @var{S}. The fields of @var{S} are passed to the function @var{func}
28 ## individually. 28 ## individually.
29 ## 29 ##
30 ## @code{structfun} accepts an arbitrary function @var{func} in the form of 30 ## @code{structfun} accepts an arbitrary function @var{func} in the form of
31 ## an inline function, function handle, or the name of a function (in a 31 ## an inline function, function handle, or the name of a function (in a
32 ## character string). In the case of a character string argument, the 32 ## character string). In the case of a character string argument, the
33 ## function must accept a single argument named @var{x}, and it must return 33 ## function must accept a single argument named @var{x}, and it must return
34 ## a string value. If the function returns more than one argument, they are 34 ## a string value. If the function returns more than one argument, they are
35 ## returned as separate output variables. 35 ## returned as separate output variables.
36 ## 36 ##
37 ## If the parameter "UniformOutput" is set to true (the default), then the 37 ## If the parameter "UniformOutput" is set to true (the default), then the
38 ## function 38 ## function
39 ## must return a single element which will be concatenated into the 39 ## must return a single element which will be concatenated into the
40 ## return value. If "UniformOutput" is false, the outputs are placed into a 40 ## return value. If "UniformOutput" is false, the outputs are placed into a
41 ## structure 41 ## structure
42 ## with the same fieldnames as the input structure. 42 ## with the same fieldnames as the input structure.
43 ## 43 ##
44 ## @example 44 ## @example
45 ## @group 45 ## @group
46 ## s.name1 = "John Smith"; 46 ## s.name1 = "John Smith";
47 ## s.name2 = "Jill Jones"; 47 ## s.name2 = "Jill Jones";
48 ## structfun (@@(x) regexp (x, '(\w+)$', "matches")@{1@}, s, 48 ## structfun (@@(x) regexp (x, '(\w+)$', "matches")@{1@}, s,
49 ## "UniformOutput", false) 49 ## "UniformOutput", false)
50 ## @result{} 50 ## @result{}
51 ## @{ 51 ## @{
52 ## name1 = Smith 52 ## name1 = Smith
53 ## name2 = Jones 53 ## name2 = Jones
54 ## @} 54 ## @}
55 ## @end group 55 ## @end group
56 ## @end example 56 ## @end example
57 ## 57 ##
58 ## Given the parameter "ErrorHandler", @var{errfunc} defines a function to 58 ## Given the parameter "ErrorHandler", @var{errfunc} defines a function to
59 ## call in case @var{func} generates an error. The form of the function is 59 ## call in case @var{func} generates an error. The form of the function is
60 ## 60 ##
61 ## @example 61 ## @example
62 ## function [@dots{}] = errfunc (@var{se}, @dots{}) 62 ## function [@dots{}] = errfunc (@var{se}, @dots{})
63 ## @end example 63 ## @end example
64 ## 64 ##
65 ## @noindent 65 ## @noindent
66 ## where there is an additional input argument to @var{errfunc} relative to 66 ## where there is an additional input argument to @var{errfunc} relative to
67 ## @var{func}, given by @var{se}. This is a structure with the elements 67 ## @var{func}, given by @var{se}. This is a structure with the elements
68 ## "identifier", "message" and "index", giving respectively the error 68 ## "identifier", "message" and "index", giving respectively the error
69 ## identifier, the error message, and the index into the input arguments 69 ## identifier, the error message, and the index into the input arguments
70 ## of the element that caused the error. For an example on how to use 70 ## of the element that caused the error. For an example on how to use
71 ## an error handler, @pxref{doc-cellfun, @code{cellfun}}. 71 ## an error handler, @pxref{doc-cellfun, @code{cellfun}}.
72 ## 72 ##
73 ## @seealso{cellfun, arrayfun, spfun} 73 ## @seealso{cellfun, arrayfun, spfun}
74 ## @end deftypefn 74 ## @end deftypefn
75 75
76 function varargout = structfun (func, S, varargin); 76 function varargout = structfun (func, S, varargin);
110 endif 110 endif
111 endfunction 111 endfunction
112 112
113 113
114 %!test 114 %!test
115 %! s.name1 = "John Smith"; 115 %! s.name1 = "John Smith";
116 %! s.name2 = "Jill Jones"; 116 %! s.name2 = "Jill Jones";
117 %! l.name1 = "Smith"; 117 %! l.name1 = "Smith";
118 %! l.name2 = "Jones"; 118 %! l.name2 = "Jones";
119 %! o = structfun (@(x) regexp (x, '(\w+)$', "matches"){1}, s, 119 %! o = structfun (@(x) regexp (x, '(\w+)$', "matches"){1}, s,
120 %! "UniformOutput", false); 120 %! "UniformOutput", false);
121 %! assert (o, l); 121 %! assert (o, l);
122 122
123 %!function [a, b] = twoouts (x) 123 %!function [a, b] = twoouts (x)
124 %! a = x + x; 124 %! a = x + x;