0

I'd like to link axes for plots on different figures. However, my plotting method is within a class designed for a GUI and plots variables based on a listbox selection. Per listbox selection, a new figure is created with the Y value being different(only magnitude and not length). What I'd like to do is be able to linkaxes for all successive plots. I noticed that the linkaxes function only works for subplots. Is there a simpler way to accomplish what I'd like to do? My code is similar to the following where the value of Y1 will change based on a listbox selection.

X1=1:100;
Y1=sqrt(X1);
figure();
plot(X1,Y1)

Thanks!

CircAnalyzer
  • 610
  • 1
  • 9
  • 29
  • linkaxes is not limited to subplots. Can't you just store the handle to each newly-created axes in a vector and pass it to linkaxes? Something like, `h = figure(); ax = cat( 1, ax, gca(h)); linkaxes(ax);` – AnonSubmitter85 Feb 16 '15 at 22:58

1 Answers1

1

So what I did to solve my problem was create two properties to store the fig and gca numbers as follows:

    FigNums=[];             % Store figure numbers during plotting
    AxNums=[];              % Store axes numbers during plotting

Then within the method, I did what AnonSubmitter85 recommended:

            app.FigNums = [app.FigNums figure()];
            app.AxNums  = [app.AxNums gca];
            plot(xvar,yvar,'DisplayName',[app.getYvarName ' vs. ' 'Time']);
            grid on;
            legend(xvarname)
            linkaxes(app.AxNums,'xy')

Works like a charm :) Thanks!

CircAnalyzer
  • 610
  • 1
  • 9
  • 29