Expand variables from a size.
a=apifun_expandfromsize(1,a) a=apifun_expandfromsize(1,a,v) a=apifun_expandfromsize(1,a,m,n) [a,b]=apifun_expandfromsize(2,a,b) [a,b]=apifun_expandfromsize(2,a,b,v) [a,b]=apifun_expandfromsize(2,a,b,m,n) [a,b,c]=apifun_expandfromsize(3,a,b,c) [a,b,c]=apifun_expandfromsize(3,a,b,c,v) [a,b,c]=apifun_expandfromsize(3,a,b,c,m,n)
a 1-by-1 or n-by-m matrix of doubles, the first parameter.
a 1-by-1 or n-by-m matrix of doubles, the second parameter.
a 1-by-1 or n-by-m matrix of doubles, the third parameter.
a 1-by-2 or 2-by-1 matrix of doubles, the required size of a, b, c.
the required number of rows
the required number of columns
a 1-by-1 matrix of floating point integers, the required number of rows
a 1-by-1 matrix of floating point integers, the required number of columns
Expand the input variables from a given size.
This function may be used to increase the flexibility of a function, which has arguments of varying dimensions.
The calling sequence
a=apifun_expandfromsize(1,a)
returns in the output a
the same as the
input a
.
This calling sequence is provided for consistency.
The calling sequence
a=apifun_expandfromsize(1,a,v)
expands the input a
into the size
required in v
.
In other words, on output, a
is a v(1)-by-v(2)
matrix of doubles, where the entries are filled by copying from the input
a
argument.
The calling sequence
a=apifun_expandfromsize(1,a,m,n)
expands the input a
into the size
required in m
and n
.
In other words, on output, a
is a m-by-n
matrix of doubles, where the entries are filled by copying from the input
a
argument.
The calling sequence
[a,b]=apifun_expandfromsize(2,a,b)
expands, if necessary, the input arguments
a
and b
,
so that, on output, the two matrices have the same size.
This common output size is the largest of the two matrices.
The calling sequences
[a,b]=apifun_expandfromsize(2,a,b,v) [a,b]=apifun_expandfromsize(2,a,b,m,n)
expand both a
and b
to the size defined in v
or m
and
n
.
The calling sequence
[a,b,c]=apifun_expandfromsize(3,a,b,c,...)
expands, if necessary, the input arguments
a
, b
and c
,
so that, on output, the three matrices have the same size.
The input arguments are checked so that inconsistent calls
produce errors.
For example, if a
is not a 1-by-1 matrix
of doubles, and if v
is provided,
then the size of a
is compared to the
values in v
: they must match.
For example, if a
is not a 1-by-1 matrix
of doubles, and if m
and n
are provided,
then the size of a
is compared to the
values in m
and n
: they must match.
// Expand one variable // Does nothing on a: a=apifun_expandfromsize(1,1:6) // Creates a 3-by-5 matrix of zeros : a=apifun_expandfromsize(1,0,[3 5]) // Creates a 2-by-3 matrix (i.e. does nothing) : a=apifun_expandfromsize(1,[1 2 3;4 5 6],2,3) // Creates a 2-by-3 matrix of zeros: a=apifun_expandfromsize(1,0,2,3) // Inconsistent call: this produces an error a=apifun_expandfromsize(1,[1 2;4 5],2,3) // Expand two variables // Does note change a or b : [a,b]=apifun_expandfromsize(2,1:6,(1:6).^-1) // Expands b to the size of a: [a,b]=apifun_expandfromsize(2,1:6,2) // Expand a to the size of b: [a,b]=apifun_expandfromsize(2,1,1:6) // Expand both a and b to make 3-by-5 matrices : [a,b]=apifun_expandfromsize(2,0,1,[3 5]) // Expand a to the size of b : [a,b]=apifun_expandfromsize(2,1,[1 2 3;4 5 6],2,3) // Expand b to the size of a : [a,b]=apifun_expandfromsize(2,[1 2 3;4 5 6],0.1,2,3) // Expand both a and b to make two 2-by-3 matrices : [a,b]=apifun_expandfromsize(2,0,1,2,3) // Does nothing on a and b : [a,b]=apifun_expandfromsize(2,[1 2 3;4 5 6],[1 2 3;4 5 6],2,3) // Expand two variables // Expands b to the size of a and c: [a,b,c]=apifun_expandfromsize(3,1:6,2,(1:6).^2) // Inconsistent call: this produces an error. // [a,b]=apifun_expandfromsize(2,[1 2;4 5],[1 2 3;4 5 6]) // A practical use-case. // The function produces normal random numbers. function X=myfunction(mu, sigma, m, n) [mu,sigma]=apifun_expandfromsize (2,mu,sigma,m,n) u=grand(m,n,"unf",0,1) X=cdfnor("X",mu,sigma,u,1-u) endfunction // Creates a 3-by-5 matrix: both mu and sigma // are expanded into two 3-by-5 matrices. X=myfunction(1,2,3,5) // Creates a 3-by-5 matrix. // sigma is expanded to a 3-by-5 matrix. X=myfunction(12*ones(3,5),2,3,5) | ![]() | ![]() |