Why do I receive an error when selecting a new design variable set in Simulink?
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Michael Murphy
el 2 de Ag. de 2016
Comentada: Artem Artem
el 27 de Nov. de 2023
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 comentarios
Swarooph
el 3 de Ag. de 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).
Respuesta aceptada
Swarooph
el 4 de Ag. de 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).
1 comentario
Artem Artem
el 27 de Nov. de 2023
I got the same error. But I don't have the code. I work with the Simulink scheme.
Más respuestas (0)
Ver también
Categorías
Más información sobre Manual Performance Optimization en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!