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 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'}}
operator ,, operator ;, replist
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'}) true islist({}) true islist([]) false ischar('') false
isstruct, isnumeric, ischar, islogical, isempty
Conversion from list to numeric array.
A = list2num(list)
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.
list2num({1, 2+3j, 4:6}) 1 2+3j 4 5 6
num2list, operator [], operator ,
Function evaluation for each element of a list
(listout1,...) = map(fun, listin1, ...)
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. fun is the name of a function as a string, a function reference, or 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} (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 map(@atan2, {1}, {2,3}) {0.4636,0.3218}
apply, cellfun, for, inline, operator @
Conversion from array to list.
list = num2list(A) list = num2list(A, dim)
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.
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]}
Replicate a list.
listout = replist(listin, n)
replist(listin,n) makes a new list by concatenating n copies of list listin.
replist({1, 'abc'}, 3) {1,'abc',1,'abc',1,'abc'}