Apply function with multiple input variables to table entry

17 visualizzazioni (ultimi 30 giorni)
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)

Risposta accettata

Fangjun Jiang
Fangjun Jiang il 29 Mag 2020
function_handle might be what you need.
  1 Commento
Peter Stroppa
Peter Stroppa il 7 Giu 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)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Tables in Help Center e File Exchange

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by