Problem with plotting using a GUI and Simulink

2 visualizaciones (últimos 30 días)
Paul
Paul el 25 de Abr. de 2012
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

Respuesta aceptada

Kaustubha Govind
Kaustubha Govind el 25 de Abr. de 2012
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 comentarios
Paul
Paul el 27 de Abr. de 2012
I went back to your earlier advice and used listners.
At first it worked perfectly . Now for some reason the listener function is failing to be called even though the event listener is active on the desired block. The simulation is running smoothly it just seems that this function is never called although it does not seem to call any errors.
Below is the code i have used
set_param('manualflight','StartFcn','localAddEventListener');
function eventhandle=localAddEventListener
eventhandle=add_exec_event_listener('manualflight/2dplot','PostDerivatives',@LocalEventListner);
function LocalEventListner(block,eventdata)
global new_xdata % makes new_x data a global point
global new_ydata % make new_y data a global thing
xdata = (block.InputPort(1).Data); %imports x data from simulink
ydata = (block.InputPort(2).Data); %imports y data from simulink
new_xdata=[xdata,new_xdata]; %adds the new point to the x data array for plotting
new_ydata=[ydata,new_ydata]; %adds the new point to the y data array for plotting
%get a handle to the GUI's 'current state' window
statestxt % plots the the xy data that has been pulled
axis ([-1 1 -1 1])
% fixes the axis to the area of the vicon area
This is quite confusing as it seemed to be working perfectly last night. I then decided to work on some other things in the night and came back to test it again today and for some reason the second function seem to be failed being called.
I suspected I may had written a function i forgot about somewhere and forot about it . but when i icilated all the files on a different machine the same probelm occured.
Am i missing something very simple ?
Kaustubha Govind
Kaustubha Govind el 30 de Abr. de 2012
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).

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Event Functions en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by