Why do I receive an error when selecting a new design variable set in Simulink?
13 次查看(过去 30 天)
显示 更早的评论
I am trying to use the response optimization toolbar in Simulink, however when I go to Design Variables Set->New, the following error is thrown: "The model does not use any base or model workspace variables. Configure the model to use base or model workspace variables for optimization." I am confused as to why this is occurring, because when I select Model Explorer and look at the base workspace, it contains all the variables present in the model (although the model workspace is empty). How can I fix this error?
Thanks, Michael
4 个评论
Swarooph
2016-8-3
Hello Michael,
I think I see what the problem is. There are 2 things at work here. First point, you may already know, so pardon me if it feels basic. Second point, probably answers your question.
1. When you create a variable called T in the base workspace, it just lives there. There is no connection to the model yet. Now, to reference this variable in the model, you need to specify this variable name in the block parameter where you want it to be. For e.g. If I want a gain block to have the value of the variable T, I would do the following. Double click on the gain block and then set the gain value to the variable name T. Screenshot below:
Now when you do Simulink.FindVars as in my first comment, you would see that the model is using the variable T.
2. When you use the set_param command (instead of the interactive way above), you are setting the the block parameter to a string. In your code above when you do num2str(T), MATLAB evaluates the variable name T to its numerical value (1.02 in this case) and passes the string '1.02' to the block. You can verify this by running this command and then double clicking the block to see whether it displays 1.02 or the variable name T. Here is where lies the problem. Simulink Design Optimization (SDO) expects actual variable name but now it sees only this number. It cannot retrace it to the variable T in the workspace. So to make this work in your case, you could rewrite your set_param command to the following:
set_param('Complete_Lumped_Parameter_Model/T','value', 'T');
In this case, we are passing the string 'T' to the block. Now the variable name is being passed as opposed to its value. When you execute this command and then look at the block parameters, you will see now it says T instead of the numerical value 1.02. After this change SDO should stop throwing that error. (You can do Simulink.FindVars to confirm this as well).
采纳的回答
Swarooph
2016-8-4
Hello Michael,
I think I see what the problem is. There are 2 things at work here. First point, you may already know, so pardon me if it feels basic. Second point, probably answers your question.
1. When you create a variable called T in the base workspace, it just lives there. There is no connection to the model yet. Now, to reference this variable in the model, you need to specify this variable name in the block parameter where you want it to be. For e.g. If I want a gain block to have the value of the variable T, I would do the following. Double click on the gain block and then set the gain value to the variable name T. Screenshot below:
Now when you do Simulink.FindVars as in my first comment, you would see that the model is using the variable T.
2. When you use the set_param command (instead of the interactive way above), you are setting the the block parameter to a string. In your code above when you do num2str(T), MATLAB evaluates the variable name T to its numerical value (1.02 in this case) and passes the string '1.02' to the block. You can verify this by running this command and then double clicking the block to see whether it displays 1.02 or the variable name T. Here is where lies the problem. Simulink Design Optimization (SDO) expects actual variable name but now it sees only this number. It cannot retrace it to the variable T in the workspace. So to make this work in your case, you could rewrite your set_param command to the following:
set_param('Complete_Lumped_Parameter_Model/T','value', 'T');
In this case, we are passing the string 'T' to the block. Now the variable name is being passed as opposed to its value. When you execute this command and then look at the block parameters, you will see now it says T instead of the numerical value 1.02. After this change SDO should stop throwing that error. (You can do Simulink.FindVars to confirm this as well).
1 个评论
Artem Artem
2023-11-27
I got the same error. But I don't have the code. I work with the Simulink scheme.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Manual Performance Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!