Function evaluation with arguments in lists.
listout = apply(fun, listin) listout = apply(fun, listin, nargout)
listout=apply(fun,listin) evaluates function fun with input arguments taken from the elements of list listin. Output arguments are grouped in list listout. Function fun is specified either by its name as a string or by an inline function.
The number of expected output arguments can be specified with an optional third input argument nargout.
apply('min', {5, 7}) {5} apply('size',{magic(3)},2) {3, 3} apply(inline('2*x+3*y','x','y'), {5, 10}) {40}
map, feval, inline, operator @
List of fields of a structure.
fields = fieldnames(strct)
fieldnames(strct) returns the field names of structure strct as a list of strings.
fieldnames(struct('a', 1, 'b', 1:5)) {'a', 'b'}
List concatenation.
list = join(l1, l2, ...)
join(l1,l2,...) joins elements of lists l1, l2, etc. to make a larger list.
join({1,'a',2:5}, {4,2}, {{'xxx'}}) {1,'a',[2,3,4,5],4,2,{'xxx'}}
Test for a list object.
b = islist(obj)
islist(obj) is true if the object obj is a list, false otherwise.
islist({1, 2, 'x'}) 1 islist({}) 1 islist([]) 0 ischar('') 0
isstruct, isnumeric, ischar, islogical, isempty
Test for the existence of a field in a structure.
b = isfield(strct, name)
isfield(strct, name) is true if the structure strct has a field whose name is the string name, false otherwise.
isfield(struct('a', 1:3, 'x', 'abc'), 'x') 1 isfield(struct('a', 1:3, 'x', 'abc'), 'X') 0
Test for a structure object.
b = isstruct(obj)
isstruct(obj) is true if the object obj is a structure, false otherwise. Structures are lists whose at least one field has a name.
isstruct(struct('a', 123)) 1 isstruct({1, 2, 'x'}) 0 a.f = 3; isstruct(a) 1
struct, isfield, islist, ischar, islogical
Function evaluation for each element of a list
listout = map(fun, listin)
listout=map(fun,listin) evaluates function fun, which accepts a single input argument and returns a single output argument, for each element of list listin. Results are grouped in list listout, which has the same size as listin. Function fun is specified either by its name as a string or by an inline function.
map('max', {[2,6,4], [7,-1], 1:100}) {6, 7, 100} map(inline('x+10'), {3,7,16}) {13, 17, 26}
Deletion of a field in a structure.
strctout = rmfield(strctin, name)
strctout=rmfield(strctin,name) makes a structure strctout with the same fields as strctin, except for field named name which is removed. If field name does not exist, strctout is the same as strctin.
x = rmfield(struct('a', 1:3, 'b', 'abc'), 'a'); fieldnames(x) b
Creation of a structure
strct = struct(fieldname1, value1, fieldname2, value2, ...)
struct builds a new structure. Input arguments are used by pairs to create the fields; for each pair, the first argument is the field name, provided as a string, and the second one is the field value.
x = struct('a', 1, 'b', 2:5); x.a 1 x.b 2 3 4 5
isstruct, isfield, rmfield, fieldnames, list