Reading a wire value from Simulink into the Command Window or GUIDE
이전 댓글 표시
I want to read the values that passes through a wire in my Simulink model.
This value should be displayed in a text field on a MATLAB GUI (it's the water level in a tank that is acquired every 100 ms).
I found out about get_param instruction, but until now I only managed to get the values from constants and transfer functions; example: get_param('main/Constant','Value') ; get_param('main/Transfer Function','Denominator').
How do I address a wire and its property list (value)?
The data is generated by an OPC Read block, passing through a subsystem using an Out port.
채택된 답변
추가 답변 (1개)
River Rock
2012년 8월 21일
0 개 추천
댓글 수: 4
Kaustubha Govind
2012년 8월 21일
Yes, there is an event-listener mechanism that will invoke your callback every time there is a new output. Please see the "Listening for Method Execution Events" section in the page I linked above.
River Rock
2012년 8월 22일
편집: River Rock
2012년 8월 22일
Kaustubha Govind
2012년 8월 22일
Is fetch_data part of the GUI function? I think that it should indeed be a standalone function. You can cache the GUI "handles" object onto the block's UserData. Haven't tested this myself, but how about:
In GUI file:
function pushbutton1_Callback(hObject, eventdata, handles)
set_param('main/nivel/MATLAB Function', 'UserData', handles);
set_param('main','SimulationCommand','start');
iev = add_exec_event_listener('main/nivel/MATLAB Function','PostOutputs',@fetch_data);
In a standalone function:
function fetch_data(block, eventData)
handles = get_param(block.BlockHandle,'UserData');
set(handles.text3,'String','does_it_work');
River Rock
2012년 8월 23일
카테고리
도움말 센터 및 File Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!