Apply function with multiple input variables to table entry

10 vues (au cours des 30 derniers jours)
Peter Stroppa
Peter Stroppa le 29 Mai 2020
Commenté : Peter Stroppa le 7 Juin 2020
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)

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by