<< apifun_expandfromsize Support apifun_keyvaluepairs >>

Apifun >> Apifun > Support > apifun_expandvar

apifun_expandvar

Expand variables so that they all have the same shape.

Calling Sequence

ovar1=apifun_expandvar(ivar1)
[ovar1,ovar2]=apifun_expandvar(ivar1,ivar2)
[ovar1,ovar2,ovar3]=apifun_expandvar(ivar1,ivar2,ivar3)
[ovar1,ovar2,ovar3,...]=apifun_expandvar(ivar1,ivar2,ivar3,...)

Parameters

ivar1 :

a matrix of doubles, the input variable #1

ovar1 :

a matrix of doubles, the output variable #1

Description

This function expands input arguments of computationnal functions. This function provides flexiblity for functions which have sets of arguments with the same goal.

On input, the input arguments ivar1, ivar2, etc... may have different dimensions. On output, the output arguments ovar1, ovar2, etc... all have the same dimensions.

For example ivar1 may be a m-by-n matrix and ivar2 may be a scalar (actually, a 1-by-1 matrix). In this case, the output variable ovar1 is a copy of ivar1, but ovar2 is a matrix, with the same size as ivar1, and all entries set to ivar2.

If two matrices or more are input arguments, these matrices must have the same dimensions: if not, an error is generated.

Examples

// Expand ovar1 to [1 1 1]
[ovar1,ovar2]=apifun_expandvar ( 1,[2 3 4] )

// Expand ovar2 to [4 4 4]
[ovar1,ovar2]=apifun_expandvar ( [1 2 3],4 )

// Expand ovar2 to [4 4 4]'
[ovar1,ovar2]=apifun_expandvar ( [1 2 3]',4 )

// Error case
// a and b are matrices: they must have the same size.
[a,b]=apifun_expandvar ( [1;2;3;4],[1;2] )

// A practical use-case.
// The function f has three arguments: x, a, b
function y=myfunction(x, a, b)
[a,b]=apifun_expandvar ( a,b )
y = x*a+b
endfunction
// Regular use
x = 2;
y = myfunction(x,1,2)
// Extended use-cases
y = myfunction(x,[1;2;3;4],2)
y = myfunction(x,2,[1;2;3;4])
// Errors
y = myfunction(x,[1;2;3;4],[1;2])

Authors


<< apifun_expandfromsize Support apifun_keyvaluepairs >>