Hi, I'm using four listeners in my GUI and I'm trying to plot them on four different axes. However, they are always plotted on the same axes. I created four axes, but the data is always plotted on the last axes (axes currenty). I've tried to pass the handles to the function, but it hasn't worked. Below, I'm sending my program. I hope someone can help me with this problem.
function eixoY_Callback(hObject, eventdata, handles)global valor_eixoY;valor_eixoY = roundn(get(handles.eixoY,'Value'),-1);set(handles.string_eixoY,'String',num2str(valor_eixoY));if (valor_eixoY > 2.5 && valor_eixoY <= 5) axisY = ((valor_eixoY - 2.5)*(24-0))/((5-2.5)+0); set_param('Model_CMH_R9/VaL','Value',num2str(axisY)); guidata(hObject,handles);end if (valor_eixoY == 2.5) axisY = 0; set_param('Model_CMH_R9/VaL','Value',num2str(axisY)); guidata(hObject,handles);end if (valor_eixoY >= 0 && valor_eixoY < 2.5) axisY = ((valor_eixoY - 2.5)*(-24-0))/((0-2.5)+0); set_param('Model_CMH_R9/VaL','Value',num2str(axisY)); guidata(hObject,handles);end %-------------------------------------------------------------------------------------------------------------------------------------------------
function pushbutton_StartStop_Callback(hObject, eventdata, handles)global ModelName phmystring = get(hObject,'String');status = get_param(ModelName,'SimulationStatus');if strcmp(mystring,'Start Simulation') if strcmp(status,'stopped') set_param(ModelName,'StopTime','inf'); set_param(ModelName,'SimulationMode','normal'); set_param(ModelName,'BlockReduction','off'); set_param(ModelName,'StartFcn','localAddEventListener'); set_param(ModelName,'SimulationCommand','start') end set(handles.pushbutton_StartStop,'String','Stop Simulation')% cla(handles.axes1)
% cla(handles.axes2)
% Create a line handle
ph(1) = line(0,0); ph(2) = line(0,0); ph(3) = line(0,0); ph(4) = line(0,0);elseif strcmp(mystring,'Stop Simulation') if strcmp(status,'running') set_param(ModelName, 'SimulationCommand', 'stop') end set(handles.pushbutton_StartStop,'String','Start Simulation')else warning('Unrecognized string for pushbutton_startstop') endassignin('base','GUI_Joystick_handles',handles)assignin('base','StartStop_hObject',handles.pushbutton_StartStop)%-------------------------------------------------------------------------------------------------------------------------------------------------function eventhandle = localAddEventListenereventhandle(1) = add_exec_event_listener('Model_CMH_R9/MotorR', ... 'PostOutputs', @localEventListener1);eventhandle(2) = add_exec_event_listener('Model_CMH_R9/MotorL', ... 'PostOutputs', @localEventListener2);eventhandle(3) = add_exec_event_listener('Model_CMH_R9/Veloc', ... 'PostOutputs', @localEventListener3); eventhandle(4) = add_exec_event_listener('Model_CMH_R9/Rot', ... 'PostOutputs', @localEventListener4); %-------------------------------------------------------------------------------------------------------------------------------------------------function localEventListener1(block, eventdata)% hFigure = GUI_Joystick();
% handles = guidata(hFigure);
global ph;simTime = block.CurrentTime;simData = block.OutputPort(1).Data;xData = get(ph(1),'XData');yData = get(ph(1),'YData');n = 100000;if length(xData) < n newXData = [xData simTime]; newYData = [yData simData];else newXData = [xData(2:end) simTime]; newYData = [yData(2:end) simData];endset(ph(1),'XData',newXData,'YData',newYData);% plot(handles.axes1,newXData,newYData);
%-------------------------------------------------------------------------------------------------------------------------------------------------function localEventListener2(block, eventdata)% hFigure = GUI_Joystick();% handles = guidata(hFigure);global phsimTime = block.CurrentTime;simData = block.OutputPort(1).Data;xData = get(ph(2),'XData');yData = get(ph(2),'YData');n = 100000;if length(xData) < n newXData = [xData simTime]; newYData = [yData simData];else newXData = [xData(2:end) simTime]; newYData = [yData(2:end) simData];endset(ph(2),'XData',newXData,'YData',newYData);% plot(handles.axes2,newXData,newYData);
%-------------------------------------------------------------------------------------------------------------------------------------------------function localEventListener3(block, eventdata)% hFigure = GUI_Joystick();% handles = guidata(hFigure);global ph;simTime = block.CurrentTime;simData = block.OutputPort(1).Data;xData = get(ph(3),'XData');yData = get(ph(3),'YData');n = 100000;if length(xData) < n newXData = [xData simTime]; newYData = [yData simData];else newXData = [xData(2:end) simTime]; newYData = [yData(2:end) simData];endset(ph(3),'XData',newXData,'YData',newYData);% plot(handles.axes3,newXData,newYData);
%-------------------------------------------------------------------------------------------------------------------------------------------------function localEventListener4(block, eventdata)% hFigure = GUI_Joystick();% handles = guidata(hFigure);global ph;simTime = block.CurrentTime;simData = block.OutputPort(1).Data;xData = get(ph(4),'XData');yData = get(ph(4),'YData');n = 100000;if length(xData) < n newXData = [xData simTime]; newYData = [yData simData];else newXData = [xData(2:end) simTime]; newYData = [yData(2:end) simData];endset(ph(4),'XData',newXData,'YData',newYData);% plot(handles.axes4,newXData,newYData);
Best Answer