1

I have a GUIDE GUI (lets call it "Main GUI"), that is having a while loop and this while loop calls the plot every time.

Now I am calling an external GUI from this Main GUI

I know that by setting the windowstyle to "modal" will make the the external GUI to stay on top always even though the while loop is calling the plot function(even though plot is treated as a seperate figure).

Please refer this question Which has the problem code

The problem here is,

while (i < 1000)
    yf = rand(1);
    y = [y, yf];
    iif = [i,iif];
    i = i + 1;
    plot(iif,y);
    %Calling external GUI
    if (get(handles.pushbutton, 'Value') == 1)
        external_gui;
    end
    pause(0.001);
end

while the "while loop" is running, if I have a plot and an external function inside the same while loop, the plot figure is refreshed every-time and so the external gui(considering the user has pressed the pushbutton).

This repeated refreshing of two figures makes the adverse effect.

How to make the plot figure as a background figure, which should not bother the external figure ? [Meaning, the plot should go on plotting in the background so, if the user has enabled the external GUI - this external GUI figure should be left alone so there is no repeated refreshing of figure will take place]

I hope I made the point clear, please let me know if you need more explanation. Thanks.

Edit: (As per the suggestion)

h = plot(iif,y);
while (i < 1000)
    yf = rand(1);
    y = [y, yf];
    iif = [i,iif];
    i = i + 1;
    set(h,'XData',iif,'YData',y);
    %Calling external GUI
    if (get(handles.pushbutton, 'Value') == 1)
        external_gui;
    end
    pause(0.001);
end

It is not making any difference.

Community
  • 1
  • 1
cppiscute
  • 707
  • 2
  • 10
  • 33
  • 3
    Don't call `plot` in a loop. [Adjust the `XData` and `YData` properties of the lineseries](http://stackoverflow.com/questions/13102654/how-should-i-update-the-data-of-a-plot-in-matlab). – sco1 Mar 29 '16 at 13:17
  • You can prepare your plot as `LineHandle=plot(iif,y)` and `set(external_gui,'visible','off')`. Then in the callback instead of plot use `set(PassedLineHandle,'xdata',X,'ydata',Y)` and `set(PassedExternalGUI,'visible','on') – Crowley Mar 29 '16 at 13:19
  • Your `pause` command is making the GUI refresh, therefore if the figure that the plot is acting on is visible it will get updated. – matlabgui Mar 29 '16 at 13:48
  • @matlabgui....Actually in my main code I dont have pause, i am using in the dummy code, just to see the plotting in real-time. In my main code I have a drawnow function, I am using drawnow becuase I have to refresh the slider components. may be the drawnow is making this refresh ? hmm I will check it. – cppiscute Mar 29 '16 at 13:51
  • @excaza....I tried setting the x and y data instead the calling plotting everytime, but it is not making any difference. The external_gui(provided user pressed the push button and opened it) just wobbles as the while loop runs – cppiscute Mar 29 '16 at 13:55
  • @excaza... sorry it does work, the problem was i still had "axes(handles.axes)" in the while loop. Thanks. – cppiscute Mar 29 '16 at 14:04

0 Answers0