Apply function with multiple input variables to table entry

17 Ansichten (letzte 30 Tage)
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)

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 29 Mai 2020
function_handle might be what you need.
  1 Kommentar
Peter Stroppa
Peter Stroppa am 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)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by