Using OpenFcn to change Simulink mask parameters

Hi,
i have a Simulink mask wich I am using to change parameters of a struct. The parameters of the struct can be modified ba the mask or via a matlab-script. If the parameters of the struct are changed by the script, the parameters in the mask won't be changed. I wanted to try using 'OpenFcn' from BlockProperties of my subsystem to set the mask parameters to those values contained in my struct. At first, I tried a very simple code to see, if I can run some code and open the mask in addition to that.
My Code in the OpenFcn:
disp('LoaderWagon') % to check if the callback works
%Path=Mdl.implement.LibraryPath.blk
Path_testframe='Verification_Trailer' % name of the Library (Trailer) in the testframe model (Verification_Trailer/Implement/...)
Path_trailer='Verification_Trailer/Implement/Trailer'
The code above works. The following code cann not be executed:
open_system('Path_testframe')
disp('1of3') % to see in the previous command works
open_system('Path_trailer')
disp('2of3')
set_param(Path_trailer,'h_G',num2str(h_G));
Simulink gives the foloowing error-message: Recursion detected in the OpenFcn of 'Verification_Trailer/Implement/Trailer'.
Is there anyone who knows how to solve this problem?
Greetings

Answers (1)

Just a comment:
If I delete the code above and type in the folowing code, the parameters of the mask will be changed when running the OpenFcn of the block (doubleclick on the block).
h_G=1
set_param(gcb,'h_G',num2str(h_G));
But there is one problemn remaining: the mask will not open after running the OpenFcn. Is there anyone who knows a solution for this problem?
Greetings

Categories

Products

Asked:

on 4 Mar 2020

Commented:

Run
on 9 Feb 2021

Community Treasure Hunt

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

Start Hunting!