Read result from Simulink to GUI with get_param

19 次查看(过去 30 天)
Hi,
I wonder if there is anyway I could read the data from simulink and display it on Matlab GUI. I have Display block in simulink that can display the reading correctly, also I have found out a function called get_param, but it doesn't allow me to read the data from simulink.
May I know if this function get_param works in my case, or I have other way to do it?
Thank you.

采纳的回答

Bhavana Sapparapu
编辑:Bhavana Sapparapu 2023-1-4
Hi,
I understand that you are trying access data from a Simulink model and display it on MATLAB GUI. As you have mentioned, you can use the "get_param" method to achieve this.
Following is a workflow that I have tried using the get_param method:
  1. Firstly, I have created a Simulink model with a Sine wave source block and connected it to a Display block.
  2. Then I ran the model and tried accessing the Display block's reading from the MATLAB command line using these commands:
% Get access to the Simulink runtime object
>> rto = get_param(gcb, 'RuntimeObject');
% Note the current time instance
>> currentTime = rto.CurrentTime
% Display block's reading
>> blockData = rto.OutputPort(1).Data
Following images illustrate the above workflow (window on left is the MATLAB command window and on to the right is the Simulink model in its runtime).
The second screenshot is taken few seconds after the first and I was able to access the real-time reading of the Display block.
Also, if you are trying to display the Simulink data on a GUI in real-time, depending on your use case, you might need to use event listeners as well. To know more about this please have a look at the following MATLAB Answers posts:
1. Updating GUI with data from a Simulink model:
2. Get value from a running Simulink model to MATLAB GUI:
3. More about using event listeners:
4. App Designer to control a Simulink Model and read back model data:
Lastly, you can always use the "Output Port" blocks or the "To Workspace" blocks from Simulink to access data from a model in MATLAB.
I hope this helps.
  1 个评论
gdz
gdz 2023-1-13
Thank you for the reply. I have encountered a new issue when I display in other way. https://www.mathworks.com/matlabcentral/answers/1893255-reading-data-from-simulink-to-gui-using-event-listener

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Sources 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by