Getting handle for interpreted MATLAB function in Simulink ?

Hi,
I am building a GUI for a Simulink model that contains an Interpreted MATLAB Function block. I want to update the variables inside the MATLAB function of the Interpreted MATLAB Function block using the GUI. But I can't get the handle for the Interpreted MATLAB Function block. Any ideas on how to do this ?

 Accepted Answer

Hello,
How do you try to catch the handle? Using get_param($blockRoot,'handle'), I catch the handle.
Using set_param($blockRoot, 'MATLABFcn', fcnName), I can change the function in the mask of the Interpreted Matlab function.

4 Comments

Hi, I didn't understand what you meant by $blockRoot ? Could you please explain that part ?
I found Block Path Names by get_param('modelName','Type','Block'), and for the Interpreted MATLAB Fcn I got [1X30 char]
$blockRoot is a char containing the block path name. You have to find a way to get this char, but I don't think is using "get_param('modelName','Type','Block')" that you can catch it.
You can try to use find_system('modelName', 'BlockType', 'MATLABFcn'), which is a command which allow you to find all "Interpreted MATLAB Function" in your model (it returns an array of char containing the path of each interpreted MATLAB Function blocks present in your model).
Is it helping you?
I tried the command find_system('modelName','BlockType','MATLABFcn'). I got the result in a variable s as [1x30 char]. I tried to use this char string in set_param by doing set_param(s,'MATLABFcn','functionname') but it gave a 'Invalid Simulink object specifier' error.
Hi, I finally got how to do this, I did :
s = find_system('modelName','BlockType','MATLABFcn')
a = get_param(s,'Handle')
set_param(a{1},'MATLABFcn','functionname')
Thanks for your help. However, I guess changing the variables inside the MATLAB function cannot be done programmatically

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!