Why do I receive an error when selecting a new design variable set in Simulink?

13 views (last 30 days)
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 Comments
Swarooph
Swarooph on 3 Aug 2016
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).

Sign in to comment.

Accepted Answer

Swarooph
Swarooph on 4 Aug 2016
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).

More Answers (0)

Categories

Find more on Manual Performance Optimization in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!