What I would like to achieve in Matlab is the following:
I have a function which takes some inputs.
f(x,y)
Now I have a list of which I would like to pass to the function in which each entry stands for one input of the functions.
f(x,y) = f([x,y])
I know that this is possible in Python like this:
f(x,y) = f(*[x,y])
What do I do in Matlab?
Thank you!
You can use a cell array. If x = {a,b}
then f(x{:})
is equivalent to f(a,b)
. Under the hood matlab automatically expand f(x{:})
as f(x{1},x{2},...)
For example, if we want to concatenate several strings:
x1 = 'A'
x2 = 'B'
x3 = 'C'
s = strcat(x1,x2,x3) % s = 'ABC'
is equivalent to
x = {'A','B','C'} % Our cell
s = strcat(x{:}) % s = 'ABC'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.