0

In app designer (MATLAB) I have two graphs I want to display ontop of eachother. This is what i did:

plot(app.UIAxes,(1:length(app.var.OEch))/app.var.OE_Fs,app.var.OEch,'Color',[0,0.7,0.9])

st=app.var.st;
hold on
for ss = 1:length(st)
plot(app.UIAxes,[st(ss);st(ss)],[50;250], 'r');
end
hold off

If I were to get rid of the app.UIAxes in the for loop, it would work and graph both graphs separately, but I want it to be able to graph it on the UIAxes. Currently, I just see a white screen where my plotted graph should be if I were to run this.

Paolo
  • 21,270
  • 6
  • 38
  • 69
A.B.
  • 81
  • 6
  • As a general rule: it's best to pass an axes hand to `hold`. Other than that, the fail-safe way to do this would be to call `plot` just once: `plot(hAx, x1, y1, x2, y2, ....)`. – Dev-iL Jun 10 '19 at 15:21
  • Would hax be UIAxes in this case? And I can't really call plot just once because I have a for loop. – A.B. Jun 10 '19 at 15:36

1 Answers1

1

Replace hold on with hold(app.UIAxes, 'on');

hold(app.UIAxes, 'on');
for ss = 1:length(st)
    plot(app.UIAxes,[st(ss);st(ss)],[50;250], 'r');
end
hold(app.UIAxes, 'off');

%Add drawnow command (just in case...).
drawnow

The reason you need to use hold(app.UIAxes, 'on');, is that hold on applies "current axes", and in GUI application, the focus may change to other axes (when you have more than one axes).

Example using hold on:
enter image description here

Example using hold(app.UIAxes, 'on'):
enter image description here

Rotem
  • 30,366
  • 4
  • 32
  • 65