RL Agent Not Found and Keeps Disappearing From Base Workspace
5 views (last 30 days)
Show older comments
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
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?
Accepted Answer
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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!