How to specify other Simulink Parameters through the GUI

Specifying other Simulink Parameters through the GUI is not a difficult task. In this section of the tutorial, I will provide an example on how to do this. You can download the source files here if you do not want to read through the tutorial. Let’s say that we want to add the following capabilities to our GUI:

  • set simulation time
  • set sample time
  • set the time when the unit step occurs
  • designate the output parameter names
  1. First, let’s make it so the user can specify the simulation time through the GUI. It is possible to specify the start and stop time as an argument to the sim command.

    For example, if I wanted to simulate the model for a specific period of time, I would use the following command:

    sim('mass_spring',[0 simTime]);

    If no time argument is given, then the value specified within the Simulink Model is used.

    Another way of doing this is through the Simulink Model itself. To do this, we need to set the simulation time parameter to a variable. As can be seen in the image, I changed it to simTime.

    Change Simulation Time

  2. Next, double click on the “Step” block. Change the Step time field to stepTime and the Sample time field to sampleTime as shown in the image below.

    Change Source Parameters

  3. Finally, lets change the output block. Previously, the output was called yout by default. But suppose you want to give your output a more descriptive name, like displacement. Instead of using the Out1 sink, we would instead use the To Workspace sink. So go ahead and replace the old output sink with the new one.

    Change Output Port

  4. Finally, we need to modify the properties of the output sink that we just added. Double click on the component and change the Variable name field to displacement and change the Save format field to Array.

    Modify Output Parameters

  5. The Simulink model should now look like this:

    Simulink Model Updated

  6. Another thing you might want to do is to NOT limit the number of data points that result from your simulation. You can deactivate this by going to Simulation => Configuration Parameters from the Simulink Model.

    Deactivate Limit Data Points

  7. Now, lets move on to the GUI changes. I won’t go over each step. But all we have to do is add on three Static Text Components and three Edit Text Components and to rename their Tag property appropriately. I renamed the Tag property for each of the Edit Text components to: stepTime_editText, sampleTime_editText, and simTime_editText. Here’s what your GUIDE figure should look like after you make the edits:

    GUIDE Figure Updated

  8. Finally, I made some minor edits to the simulate_pushbutton_Calback function.

    function simulate_pushbutton_Callback(hObject, eventdata, handles)
     
    axes(handles.axes1)
    % get the parameters from the edit text fields
    m=str2num(get(handles.mass_editText,'String'));
    c=str2num(get(handles.damping_editText,'String'));
    k=str2num(get(handles.spring_editText,'String'));
    stepTime=str2num(get(handles.stepTime_editText,'String'));
    sampleTime=str2num(get(handles.sampleTime_editText,'String'));
    simTime=str2num(get(handles.simTime_editText,'String'));
     
    options = simset('SrcWorkspace','current');
    sim('mass_spring',[],options);
    %plot the data
    plot(tout,displacement)
    xlabel('Time')
    ylabel('Displacement')
    title('2nd Order Mass Spring System')
    grid on
  9. After you make all of these changes, you can finally test and run your GUI! Try inputting in different input parameters to test it out.

    Running the GUI

If you are unable to get your GUI/Simulink Model to work, you can download the source files here .

We encourage you explore and to play around with some of the other features within Simulink. There are a myriad of features that were not discussed, and we hope this tutorial has given you a better idea on how to use a GUI in conjunction with Simulink.

This is the end of the tutorial.

Pages: 1 2 3 4