Specifications
A GUI to Set Simulink Model Parameters
5-33
model_open(handles)
% Get the new value for the Kf Gain
NewStrVal = get(h,'String');
NewVal = str2double(NewStrVal);
% Check that the entered value falls within the allowable range
if isempty(NewVal) | (NewVal< -5) | (NewVal>0),
% Revert to last value, as indicated by KfValueSlider
OldVal = get(handles.KfValueSlider,'Value');
set(h,'String',OldVal)
else, % Use new Kf value
% Set the value of the KfValueSlider to the new value
set(handles.KfValueSlider,'Value',NewVal)
% Set the Gain parameter of the Kf Gain Block to the new value
set_param('f14/Controller/Gain','Gain',NewStrVal)
end
The callback for the Ki Current value follows a similar approach.
Running the Simulation from the GUI
The GUI Simulate and store results button callback runs the model
simulation and stores the results in the
handles structure. Storing data in the
handles structure simplifies the process of passing data to other subfunction
since this structure can be passed as an argument.
When a user clicks on the
Simulate and store results button, the callback
executes the following steps:
•Calls
sim, which runs the simulation and returns the data that is used for
plotting.
•Creates a structure to save the results of the simulation, the current values
of the simulation parameters set by the GUI, and the run name and number.
•Stores the structure in the
handles structure.
•Updates the list box
String to list the most recent run.
Here is the
Simulate and store results button callback.
function varargout = SimulateButton_Callback(h,eventdata,handles,varargin)
[timeVector,stateVector,outputVector] = sim('f14');
% Retrieve old results data structure
if isfield(handles,'ResultsData') & ~isempty(handles.ResultsData)