RL Agent Not Found and Keeps Disappearing From Base Workspace

5 views (last 30 days)
Hi, I'm using the MATLAB RL Toolbox with Simulink to train and deploy a PI controller for DC motor speed control. I exported my trained agent as "agent1" and have set my RL Agent block's Agent Object parameter to "agent1" as well.
When I export the agent, "agent1" is added to my base workspace just well.
However, when I run the model with:
sim("My_Project_Name");
"agent" suddenly disappears and I get the following error:
Error evaluating parameter 'Agent' in '...Path_To_Agent/RL Agent'
Caused by:
Unrecognized function or variable 'agent1'.
Variable 'agent1' does not exist.
I even tried saving it in another matlab file and loading it, but it doesn't make any difference.
save('myAgent.mat','agent1');
  4 Comments
Haelee
Haelee on 11 Apr 2025
Hi, 준희.
I noticed that there "clear" script inside the init function (InifFcn) in your model.
This deletes all the variables.
Would you try again commenting out "clear" and see if the issue exist?
준희
준희 on 12 Apr 2025
The issue has been solved! Thank you so much, I forgot about the initFcn..😓
Could I ask one more question while we're at it? The Speed Controller subsystem block appears yellow with a red outline and the output arrow is also red. I tried attaching a scope on the output arrow and it displayed the plot just fine, so I don't understand why the block appears like this. It happened out of nowhere as I don't remember changing anything other than just repeatedly running simulations, but I'm sure I did something wrong along the way. I just can't figure out the problem.
It's my first time using simulink and I'm on my own, so I apologize if this is a basic question. Thanks so much for the help!

Sign in to comment.

Accepted Answer

Haelee
Haelee on 14 Apr 2025
Edited: Haelee on 14 Apr 2025
Hi, 준희.
I'm glad my comments helped you resolve the error.
I looked into your model and found the same issue (where the model runs well with no error or warning in the Diagnostic Viewer but the block still has red outlines and yellow background). I suggest there might be a bug in your model.
To resolve it, you can try deleting the cache file ("/slprj") and ungrouping the subsystem, then regrouping it as explained in Gabriele Gualandi's answer in this link.
I was able to see the issue resolved with this method.
  1 Comment
준희
준희 on 5 May 2025
This solved the problem!!
Had no idea an action as simple as regrouping the subsystem would be the solution but the problem's gone!
Thank you so much for your help.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!