Why received from add_exec_event_listener data showed in new gui in matlab app designer?

351 views Asked by At

I am trying to get real-time data from simulink model and display it on gui, so I am using add_exec_event_listener in Simulink model callback as written here: https://www.mathworks.com/matlabcentral/answers/446302-how-do-i-update-a-gui-designed-in-app-designer-with-data-from-a-running-simulink-model The problem is that all the results of the function updateGUI execution is displayed in new GUI(new gui opens once, not every time function executes). The question is: how to display the received from listener data in the main gui without opening a new one. Here is code of updateGUI function.

methods (Access = public)
        
   %Listener    
        function updateGUI(app, varargin)
            % Create an object that gets the run-time value of the specified block
            rto = get_param([bdroot,'/Gain'],'RuntimeObject');
            currentTime = rto.CurrentTime;
            app.SimTime.Text = num2str(currentTime);
            % Update the GUI accordingly
            sdrData = rto.InputPort(1).Data;
            h1=plot(app.UIAxes, 1, 1,'r'); 
            sdrData=sdrData.*app.W;
            sdrFft = fftshift(fft(sdrData));
            sdrFft=20*log10((abs(sdrFft))/2048);
            % Refresh plot
            set(h1,'XData',app.freqvec);
            set(h1,'YData',sdrFft);
            refreshdata(app.UIAxes);
            drawnow;
          end 
end

Here is callback where simulink model executes.

 function StartButtonPushed(app, event)
            app.StopButton.Enable = 'on';
            app.StartButton.Enable = 'off';
            set_param('gsmAdGui2/Constant','Value',num2str(app.CenterFreqEditField.Value));
            set_param('gsmAdGui2/Constant1','Value',num2str(app.GainEditField.Value));
            out=sim('gsmAdGui2', 'StartTime','0','StopTime',num2str(app.StopTimeEditField.Value));
 end
0

There are 0 answers