en fr

Sysquake Pro – Table of Contents

Sysquake – Table of Contents

Sysquake for LaTeX – Table of Contents

List Functions

apply

Function evaluation with arguments in lists.

Syntax

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

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 by either its name as a string, a function reference, or an anonymous or inline function.

The number of expected output arguments can be specified with an optional third input argument nargout. By default, the maximum number of output arguments is requested, up to 256; this limit exists to prevent functions with an unlimited number of output arguments, such as deal, from filling memory.

With a 4th argument na (or 3rd if nargout is not specified), named arguments can be provided as a structure.

Examples

apply(@size, {magic(3)}, 2)
  {3, 3}
apply(@(x,y) 2*x+3*y, {5, 10})
  {40}

The maximum number of output arguments of min is 2 (minimum value and its index):

apply(@min, {[8, 3, 4, 7]})
  {3, 2}

Two equivalent ways of calling disp with a named argument fd to specify the standard error file descriptor 2:

disp(123, fd=2);
apply(@disp, {123}, 0, {fd=2});

See also

map, feval, inline, operator @, varargin, namedargin, varargout

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'}}
join()
  {}

See also

operator ,, operator ;, replist

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'})
  true
islist({})
  true
islist([])
  false
ischar('')
  false

See also

isstruct, isnumeric, ischar, islogical, isempty

list2num

Conversion from list to numeric array.

Syntax

A = list2num(list)

Description

list2num(list) takes the elements of list, which must be numbers or arrays, and concatenates them on a row (along second dimension) as if they were placed inside brackets and separated with commas. Element sizes must be compatible.

Example

list2num({1, 2+3j, 4:6})
  1  2+3j  4  5  6

See also

num2list, operator [], operator ,

map

Function evaluation for each element of a list

Syntax

(listout1,...) = map(fun, listin1, ...)

Description

map(fun,listin1,...) evaluates function fun successively for each corresponding elements of the remaining arguments, which must be lists or cell arrays. It returns the result(s) of the evaluation as list(s) or cell array(s) with the same size as inputs. Input lists which contain a single element are repeated to match other arguments if necessary. Function fun is specified by either its name as a string, a function reference, or an anonymous or inline function.

Examples

map('max', {[2,6,4], [7,-1], 1:100})
  {6, 7, 100}
map(@(x) x+10, {3,7,16})
  {13, 17, 26}
(nr, nc) = map(@size, {1,'abc',[4,7;3,4]})
  nr =
    {1,1,2}
  nc =
    {1,3,2}
s = map(@size, {1,'abc',[4,7;3,4]})
  s =
    {[1,1], [1,3], [2,2]}
map(@disp, {'hello', 'lme'})
  hello
  lme

Lists with single elements are expanded to match the size of other lists. The following example computes atan2(1,2) and atan2(1,3):

map(@atan2, {1}, {2,3})
  {0.4636,0.3218}

See also

apply, cellfun, for, inline, operator @

num2list

Conversion from array to list.

Syntax

list = num2list(A)
list = num2list(A, dim)

Description

num2list(A) creates a list with the elements of non-cell array A.

num2list(A,dim) cuts array A along dimension dim and creates a list with the result.

Examples

num2list(1:5)
  {1, 2, 3, 4, 5}
num2list([1,2;3,4])
  {1, 2, 3, 4}
num2list([1, 2; 3, 4], 1)
  {[1, 2], [3, 4]}
num2list([1, 2; 3, 4], 2)
  {[1; 3], [2; 4]}

See also

list2num, num2cell

replist

Replicate a list.

Syntax

listout = replist(listin, n)

Description

replist(listin,n) makes a new list by concatenating n copies of list listin.

Example

replist({1, 'abc'}, 3)
  {1,'abc',1,'abc',1,'abc'}

See also

join, repmat