Apply function with multiple input variables to table entry

14 views (last 30 days)
Hi all,
thanks for your help in advance. I do have a self written function, that requires 3 input variabels. I would like to apply this function to each value of a table column, in such a way, that the first input parameter of the function is the value of the table and the other two are specified by me. Currently I am trying to use varfun for this, but unfortunately I cannot figure out how to specify the last two parameters.The situation looks following:
output = my_func(input1,input2,input3)
I would like to do something like this:
finaltable = varfun(my_func,table.column1, input2, input3)

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 29 May 2020
function_handle might be what you need.
  1 Comment
Peter Stroppa
Peter Stroppa on 7 Jun 2020
Thanks, function_handle did indeed fix my problem although it still took me some time to figure out the final way. For others, who might run into a similar problem:
helped me a lot. Also I found out, that table.columns are no longer a table but a mere array. Therefore I just used arrayfun instead of varfun in the end.
The final solution:
Solution = arrayfun(@(x) my_func(x,input1,input2), table.column1)

Sign in to comment.

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!