List and Structure Functions

apply

Function evaluation with arguments in lists.

Syntax

listout = apply(fun, listin)
listout = apply(fun, listin, nargout)

Description

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.

Examples

apply('min', {5, 7})
  {5}
apply('size',{magic(3)},2)
  {3, 3}
apply(inline('2*x+3*y','x','y'), {5, 10})
  {40}

See also

map, feval, inline, operator @

fieldnames

List of fields of a structure.

Syntax

fields = fieldnames(strct)

Description

fieldnames(strct) returns the field names of structure strct as a list of strings.

Example

fieldnames(struct('a', 1, 'b', 1:5))
  {'a', 'b'}

See also

struct, isfield, rmfield

join

List concatenation.

Syntax

list = join(l1, l2, ...)

Description

join(l1,l2,...) joins elements of lists l1, l2, etc. to make a larger list.

Examples

join({1,'a',2:5}, {4,2}, {{'xxx'}})
  {1,'a',[2,3,4,5],4,2,{'xxx'}}

See also

operator ,, operator ;

islist

Test for a list object.

Syntax

b = islist(obj)

Description

islist(obj) is true if the object obj is a list, false otherwise.

Examples

islist({1, 2, 'x'})
  1
islist({})
  1
islist([])
  0
ischar('')
  0

See also

isstruct, isnumeric, ischar, islogical, isempty

isfield

Test for the existence of a field in a structure.

Syntax

b = isfield(strct, name)

Description

isfield(strct, name) is true if the structure strct has a field whose name is the string name, false otherwise.

Examples

isfield(struct('a', 1:3, 'x', 'abc'), 'x')
  1
isfield(struct('a', 1:3, 'x', 'abc'), 'X')
  0

See also

isstruct, struct

isstruct

Test for a structure object.

Syntax

b = isstruct(obj)

Description

isstruct(obj) is true if the object obj is a structure, false otherwise. Structures are lists whose at least one field has a name.

Examples

isstruct(struct('a', 123))
  1
isstruct({1, 2, 'x'})
  0
a.f = 3;
isstruct(a)
  1

See also

struct, isfield, islist, ischar, islogical

map

Function evaluation for each element of a list

Syntax

listout = map(fun, listin)

Description

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.

Examples

map('max', {[2,6,4], [7,-1], 1:100})
  {6, 7, 100}
map(inline('x+10'), {3,7,16})
  {13, 17, 26}

See also

apply, for, inline

rmfield

Deletion of a field in a structure.

Syntax

strctout = rmfield(strctin, name)

Description

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.

Example

x = rmfield(struct('a', 1:3, 'b', 'abc'), 'a');
fieldnames(x)
  b

See also

struct

struct

Creation of a structure

Syntax

strct = struct(fieldname1, value1, fieldname2, value2, ...)

Description

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.

Example

x = struct('a', 1, 'b', 2:5);
x.a
  1
x.b
  2 3 4 5

See also

isstruct, isfield, rmfield, fieldnames, list


Copyright 1998-2001, Calerga.

All rights reserved.