Clear Filters
Clear Filters

Converting simulink blocks to code for a GUI?

4 views (last 30 days)
I would like to create a GUI in MATLAB that has two sliders that can be used to adjust the value a and b. I know I can get the GUI to open simulink and have simulink do this and then packet the information using UDP as shown in the following image:
However, I would prefer to be able to convert these simulink blocks to code in the GUI slider. More specifically, I am interested in coding the packet output block so the GUI button can send the information. Does anyone know how to do this?

Answers (2)

cr
cr on 14 May 2013
You can use set command for callbacks of GUI sliders with handles of the constant blocks to change the block parameter values. Not sure what the packet output block is, but if you are able to "send the information" from simulink, then the same can be done via GUI too using handle to the block. For more info, see gcs, gcb, set & get. You may want to read the section on programmatically using simulink models in documentation.
  1 Comment
Justin Liang
Justin Liang on 19 May 2013
Edited: Justin Liang on 19 May 2013
The packet block sends unformatted binary data. Here is the full simulink model:
So what I do here is use Packet Output to send a double value using UDP. The Packet Input block receives it and sends it to the Scope and in that Scope you will see a horizontal line with a y value equal to the double value in the Constant block.
HOWEVER, for me, I need to code both the Constant and Packet Output blocks in MATLAB for the GUI. For example, in my GUI I might have a slider that changes the value in the Constant block and also sends the information to Packet Input. I should be able to easily test this by removing the Constant and Packet Output blocks and then sliding the sliders on the GUI. This should change the graph in Scope.
Also, what documentation can I read the section on programmatically using simulink models?

Sign in to comment.


Kaustubha Govind
Kaustubha Govind on 20 May 2013
Since you'd like to execute the GUI as if it were a block, it might be best to create a custom block that opens up and reads from a GUI during simulation, and computes its outputs based on actions on the GUI. Please look into MATAB S-functions.
  1 Comment
Justin Liang
Justin Liang on 25 May 2013
Thank you for the reply, with your method Simulink has to be running right? Because for my application I would like to have the GUI run everything and send the packets.

Sign in to comment.

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!