set_param and callback argument
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I have a syntax question. I would like to use the set_param function to define a callback Startfcn of a simulink block. How can I put an argument to my Startfcn function ?
For example : modelName = 'sim_model.mdl' function_name = 'start_function' set_param(modelName,'StartFcn',function_name);
For example, my Startfcn is like this :
function start_function(abc) display(abc) end
Thnak you in advance.
0 comentarios
Respuesta aceptada
TAB
el 24 de Oct. de 2011
Where you want to put 'StartFcn' callback function, either for a block or for a whole simulink model ?
For StartFcn of a block:
Get the block handle and use with set_param(). For example
bh=gcbh; % Returns handle of current selected block
set_param(bh,'StartFcn',function_name);
For StartFunc of whole model:
Get the model handle and use with set_param(). For example
open_system(modelName);
mh=get_param(modelName_without_extension,'handle'); % Retuns model handle
set_param(mh,'StartFcn',function_name);
-------------
[ EDITED ]
abc_str=sprintf('%f',abc) % Get the value of abc in string
func_str=strcat('start_function(',abc_str,')');
set_param(mh,'StartFcn',func_str);
You can format string 'abc_str' as per data type of variable 'abc' using %d, %s etc.
0 comentarios
Más respuestas (1)
Christophe
el 24 de Oct. de 2011
5 comentarios
TAB
el 25 de Oct. de 2011
I have to again guess how your structure will be.
Please give some datails. If you can not post original data, express it with examples.
Ver también
Categorías
Más información sobre Model, Block, and Port Callbacks en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!