Convert string function to function handle with struct parameters

1 次查看(过去 30 天)
Hello, I am trying to define function handle with the following structure:
odefunc = @(t,x) myfunc(t,x,param)
where param is a struct with the following fields: param.a = matrix; param.b = vector; param.c = number; etc. This function will be used for solving ode:
[t,x] = ode45(odefunc, tspan, init);
What I am trying to do is convert string function name to actual function handle to be used in solving the ode. The following is what I tried:
===============================================
string_name = 'myfunc';
odefunc = DefineMyFunction(string_name,param);
[t,x] = ode45(odefunc,tspan,init);
function odefunc = DefineMyFunction(string_name,param)
func = str2func('@(t,x) string_name(t,x,param)');
===============================================
Of course, it is not working because struct "param" is not fed into myfunc properly. I found many good examples in case that param is not struct but a simple single variable . But, how can I construct functiona handle with struct?
Thank you for your help in advance.
  4 个评论

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by