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 件のコメント
Walter Roberson
2019 年 4 月 26 日
myfunc = str2func(string_name);
func = @(t,x) myfunc(t, x, param);
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!