Mar 19th, 2009
I recently had to make a Matlab™ subplot and wanted to link the axes of the two plots together, so that both graphs show the same range on their x-axis. Of course, there is a simple command for this in Matlab™: linkaxes. Detailed information about the command can be found on the Web-Documentation. The following code shows, how I did it in my script.
ax(1) = subplot( 4,1,1 ); plot(x) % ... ax(2) = subplot( 4,1,[2:4] ); linkaxes(ax,'x'); plot(u) % ...
It seems like, that the basic idea is to get the subplot handles (ax in the example) and connect the axes using linkaxes by specifying the subplot handle vector and the type of linkage (x,y,xy or oﬀ). As far as I ‘ve seen, there are many ways to accomplish this task, but the above method seems to be the simplest to me.