200 likes | 612 Views
Simulink and mfile. In this section, we will look at GUIs with Simulink Programming GUIs using mfiles. GUI with Simulink. GUIs can be used with Simulink to Open a Simulink file Send parameters to a Simulink file Simulate a Simulink file Extract data from a Simulink file.
E N D
Simulink and mfile In this section, we will look at GUIs with Simulink Programming GUIs using mfiles
GUI with Simulink GUIs can be used with Simulink to Open a Simulink file Send parameters to a Simulink file Simulate a Simulink file Extract data from a Simulink file
GUI with Simulink To open a Simulink file, type >>open_system(‘Filename’)
Example Create a Simulink file that outputs a sinewave Create a GUI to set the amplitude, frequency and phase shift of the sinewave. Then plot the results.
Example Make sure that your output is an Outport Note the name given to the block (you can change if you want)
Example Note these field names If you open the Sine Wave block, you get
Example Now create the GUI
Example Now program the Pushbutton Callback Open the Simulink file >>open_system(‘SimulinkExample’); The name of your Simulink file
Example Get the user entered values and set them into the Simulink file >>amp=get(handles.edit1,‘string’); >>set_param(‘SimulinkExample/Sine Wave’,‘Amplitude’,amp); ‘Filename/Blockname’ Field name (take only 1st word)
Example Get the user entered values and set them into the Simulink file >>freq=get(handles.edit2,‘string’); >>set_param(‘SimulinkExample/Sine Wave’,‘Frequency’,freq); ‘Filename/Blockname’ Field name (take only 1st word)
Example Get the user entered values and set them into the Simulink file >>phase=get(handles.edit3,‘string’); >>set_param(‘SimulinkExample/Sine Wave’,‘Phase’,phase); ‘Filename/Blockname’ Field name (take only 1st word)
Example Simulate the Simulink file >>[timeVector,stateVector,outputVector]=sim('SimulinkExample'); The 3rd output argument will give you the data of the ‘Outport’ Names you can assign
Example Plot the results >>plot(timeVector, outputVector)
GUI by programming It is also possible to create a GUI by command line programming without using GUIDE Use the command ‘uicontrol’
GUI by programming The format of programming a uicontrol is as follows >>h=uicontrol(‘Property1’,value, ‘Property2’, value,…)
GUI by programming Property Property For example, to create a Pushbutton >>h=uicontrol(‘style’,‘pushbutton’,‘units’,‘normalized’, ‘position’, [0.1 0.2 0.3 1.1]) value value value Property
GUI by programming What are the possible fields for Property? units, style, position, callback, string, fontsize, visible, enable Basically, whatever you can find when you double-click a component in GUI
GUI by programming All possible property fields Value fields
Conclusion: this course The principles of GUI in Matlab How to create a GUI using GUIDE How to output messages/dialogs How to create menus GUI with Simulink and programming Use ‘help’ commands in Matlab to know more