My simple work running Genetic Algorithm with simulink doesn't work, with error 'Unable to resolve the name... '.

1 次查看(过去 30 天)
Hi,
I'm using MATLAB R2024b Home edition, with 'Simulink', 'Global Optimization Toolbox', and 'Optimization Toolbox'.
I'm gonna run my work to find the optimum PID gain using the Genetic Algorithm(GA) that are described in my simulink configuration in the below figure.
In the simulink configuration, the 'out.ITAE', which is for 'To Workspace' block, stands for my fitness function that should be minimized through GA. The variables 'k' are gain values for PID(total 3 variables).
When I try to solve 'GA' through the command [solution, objectiveValue] = ga(@tunning,3), I got the error message 'Unable to resolve the name 'out.ITAE', as shown in the figure below.
Could you please give any comment to solve this issue?
Thank you very much in advance.

采纳的回答

Walter Roberson
Walter Roberson 2024-12-14
By default, To Workspace outputs to the base workspace. Your code assumes that out.ITAE is available in the workspace of the function rather than the base workspace.
  1 个评论
Yeonghoon
Yeonghoon 2024-12-14
Thank you for your help.
After I use 'evalin' function to load variable in the base workspace, it works OK.
function cost = tunning(k)
assignin('base','k',k);
sim('testga.slx');
temp = evalin('base','out.ITAE');
cost=temp(length(temp));
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by