MATLAB: How to get variables from GUI m-file into Simulink Model
Hey guys, I dont know if I'm wording my problem开发者_StackOverflow社区 right but I have created a GUI, an m-file and a simulink. Initially I had the variables going from the m-file into the Simulink, but now I want the user to be able to change the variables so I have created a GUI. I keep getting an error though, I dont think the variables are going from the GUI m-file to the simulink model anymore. I remember you had to set something to do it, like simset or setcurrentsim or something but I cannot remember, so I was wondering can anyone help me with this one?
Use the set_param command.
It should look something like this:
set_param('model name/block name','block type',string);
In my code I have a model called Pitch_Control with a Gain block called Pitch Rate Sensor. k2 is an integer.
set_param('Pitch_Control/Pitch Rate Sensor','Gain',num2str(k2));
I hope this helps.
set_param
works, however it is a pretty specific way and should only be used to change block settings and not to pass parameters.
What you are looking for is assignin.
You go with: assignin('base','Parametername',value);
Since Simulink imports variables from the base-workspace it does the same as your old script would have done.
精彩评论