Problem with plotting using a GUI and Simulink
古いコメントを表示
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 件)
カテゴリ
ヘルプ センター および File Exchange で General Applications についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!