Problem with plotting using a GUI and Simulink
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to Plot realtime position data On to a GUI axes. My first attempt was using a listner function but i could only plot the data if i used the method of
s=plot(x_data,y_data) set(s,'Parent',axes2)
This would result in the data being plotted but i could not discover a way of keeping my axis fixed at the point [-1,1,-1,1] for the x and y limits.The plot would shift to the amount of change in the data.
To try and overcome this i started using timer functions which would activate at a period of 0.01 seconds that would call the data from simulink.
Again i came up with the same problem. with also a further problem is that the plot would not automatically update. I had to use a push button to force update it. This makes little sense to me as the function on the timer should carry on doing this.
Can anyone help with any of my problems ? My code is below.
% --- Executes on button press in plot_data. function plot_data_Callback(hObject, eventdata, handles) % hObject handle to plot_data (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) axis_plotter=timer; set(axis_plotter,'executionmode','fixedRate') set(axis_plotter,'Period',0.01) set(axis_plotter,'TimerFcn',@plot_axis) start(axis_plotter)
function plot_axis(source,event)
global new_xdata
global new_ydata
rto = get_param('manualflight/2dplot','RuntimeObject');
ydata = rto.InputPort(1).Data ;
xdata = rto.InputPort(2).Data ;
new_xdata=[xdata,new_xdata];
new_ydata=[ydata,new_ydata];
set(axes2.handles, 'XLim', [-1,1], 'YLim', [-1,1])
set(axes2.handles,'XData',new_xData,'YData',new_yData);
I also tried
--- Executes on button press in plot_data.
function plot_data_Callback(hObject, eventdata, handles)
% hObject handle to plot_data (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axis_plotter=timer;
set(axis_plotter,'executionmode','fixedRate')
set(axis_plotter,'Period',0.01)
set(axis_plotter,'TimerFcn',@plot_axis)
start(axis_plotter)
function plot_axis(source,event)
global new_xdata
global new_ydata
rto = get_param('manualflight/2dplot','RuntimeObject');
data = rto.InputPort(1).Data ;
xdata = rto.InputPort(2).Data ;
new_xdata=[xdata,new_xdata];
new_ydata=[ydata,new_ydata];
b=plot(new_xdata,new_ydata);
set(b,'Parent',axes2)
drawnow update
This code came up with the problem of not updating and having a too small of an axis
댓글 수: 0
채택된 답변
Kaustubha Govind
2012년 4월 25일
You need to register Simulink execution event listeners for the plot to update as the simulation runs. See Listening for Method Execution Events and How can I update a GUI with values from my Simulink model as it is running?
댓글 수: 6
Kaustubha Govind
2012년 4월 30일
Are you still running your model in Normal mode? Someone on this forum mentioned recently that event listeners don't work in Accelerator mode (although I can't find this mentioned in the documentation).
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Event Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!