CircAnalyzer
CircAnalyzer

Reputation: 704

MATLAB linkaxes for different figures

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!

Upvotes: 1

Views: 2589

Answers (1)

CircAnalyzer
CircAnalyzer

Reputation: 704

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!

Upvotes: 2

Related Questions