Apply function with multiple input variables to table entry

조회 수: 10 (최근 30일)
Peter Stroppa
Peter Stroppa 2020년 5월 29일
댓글: Peter Stroppa 2020년 6월 7일
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)

채택된 답변

Fangjun Jiang
Fangjun Jiang 2020년 5월 29일
function_handle might be what you need.
  댓글 수: 1
Peter Stroppa
Peter Stroppa 2020년 6월 7일
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)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by