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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With