Is it possible to apply common axes values to existing figures?

3 views (last 30 days)
I'm attempting to open existing figures, and apply a common set of axes to the plots within each figure. But I'm not sure MATLAB will allow for this. I know of the linkaxes function as it applies to subplots. Is there a similar function that can be used for figures?
I'm attempting to do this using the following MATLAB code:
x = linspace(0,2*pi,25);
y = sin(x);
h1 = figure; % 1st figure window
stairs(x,y);
% Save the figure in the current directory
saveas(gcf,'SineWave.fig');
close;
x = linspace(0,3*pi,25);
y = sin(x);
h2 = figure; % 2nd figure window
stairs(x,y);
% Save the figure in the current directory
saveas(gcf,'SineWave2.fig');
close;
pause(1);
openfig('SineWave.fig');
openfig('SineWave2.fig');
This produces 2 figures where the y-axis varies from -1 to 1. The x-axis varies from 0 to 7 from one figure and 0 to 10 for the other.
Is there a way to make the x-axis common (for example, 0 to 12)?
Thank you.

Accepted Answer

John Chilleri
John Chilleri on 26 Jan 2017
Edited: John Chilleri on 26 Jan 2017
Hello,
You can use:
axis([x1 x2 y1 y2])
where x1 specifies the left side axis limit of the x-axis, x2 the right side axis limit of the x-axis, and similarly y1 is the bottom side axis limit of the y-axis, and y2 is the top side axis limit for the y-axis.
In your case, select your first figure then type:
axis([0 12 -1 1])
then select your second figure and do the same.
Hope this helps!

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!