Borrar filtros
Borrar filtros

Convert string function to function handle with struct parameters

1 visualización (últimos 30 días)
Hyungjin Choi
Hyungjin Choi el 20 de Abr. de 2019
Comentada: per isakson el 26 de Abr. de 2019
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 comentarios
Walter Roberson
Walter Roberson el 26 de Abr. de 2019
myfunc = str2func(string_name);
func = @(t,x) myfunc(t, x, param);

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Productos


Versión

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by