From: Camille Couzi on
Hi,
I have a problem linking axes of my 5 subplots in a figure.
I can't use linkaxes because my subplots are linked all between themselves, and linkaxes doesn't work goo when we call it many times.

My subplots are these:
sub1=subplot(5,1,1);
sub2=subplot(5,2,1);
sub3=subplot(5,3,1);
sub4=subplot(5,4,1);
sub5=subplot(5,5,1);

These are the links I want to do:
- sub1 and sub 2 are linked by X and Y axes
- sub1, sub 2 and sub5 are linked by X axes
- sub1 and sub 3 are linked by Y axes
- sub2 and sub 4 are linked by Y axes.

Any help would be great, I am stopped by this problem since many days.
Thank you!

Camille.
From: Andy on
"Camille Couzi" <camillecouzi(a)yahoo.fr> wrote in message <i3ulj9$4vc$1(a)fred.mathworks.com>...
> Hi,
> I have a problem linking axes of my 5 subplots in a figure.
> I can't use linkaxes because my subplots are linked all between themselves, and linkaxes doesn't work goo when we call it many times.
>
> My subplots are these:
> sub1=subplot(5,1,1);
> sub2=subplot(5,2,1);
> sub3=subplot(5,3,1);
> sub4=subplot(5,4,1);
> sub5=subplot(5,5,1);
>
> These are the links I want to do:
> - sub1 and sub 2 are linked by X and Y axes
> - sub1, sub 2 and sub5 are linked by X axes
> - sub1 and sub 3 are linked by Y axes
> - sub2 and sub 4 are linked by Y axes.
>
> Any help would be great, I am stopped by this problem since many days.
> Thank you!
>
> Camille.

First, at the command line, type:
>> edit linkaxes

This opens up the m-file for linkaxes for you to see. Then save a copy of this in your current directory before continuing. Now, in the local copy, make the following changes:

1. To the arguments, add a new argument (which I have called removeFlag), so the first line should look like:

function linkaxes(ax,option,removeFlag)

2. Find this part of the file (lines 62 and 63 for me):

% Remove any prior links to input handles
localRemoveLink(ax)

3. Replace it with the following:

if nargin < 3
removeFlag = true;
end

if removeFlag
% Remove any prior links to input handles
localRemoveLink(ax)
end

This will allow you to decide whether you want to remove the prior links or not. You should be warned, however, that MATLAB removes the prior links for a reason. It would be very easy to accidentally create inconsistent links, and MATLAB would produce unintended results or errors if you did so.

4. Here's a test script to see the result:

x=0:0.1:20;
y1=sin(x);
y2=0.5*sin(x);
y3=0.05*x;
y4=sin(10*x);
y5=2*x.^2-5*x+1;


sub1=subplot(5,1,1);
sub2=subplot(5,1,2); % note which argument changes from line to line
sub3=subplot(5,1,3);
sub4=subplot(5,1,4);
sub5=subplot(5,1,5);

linkaxes([sub1 sub2 sub5],'x',false);
linkaxes([sub1 sub2 sub3 sub4],'y',false);

plot(sub1,x,y1);
plot(sub2,x,y2);
plot(sub3,x,y3);
plot(sub4,x,y4);
plot(sub5,x,y5);
From: Walter Roberson on
Camille Couzi wrote:
> Hi,
> I have a problem linking axes of my 5 subplots in a figure.
> I can't use linkaxes because my subplots are linked all between
> themselves, and linkaxes doesn't work goo when we call it many times.
>
> My subplots are these:
> sub1=subplot(5,1,1);
> sub2=subplot(5,2,1);
> sub3=subplot(5,3,1);
> sub4=subplot(5,4,1);
> sub5=subplot(5,5,1);
>
> These are the links I want to do:
> - sub1 and sub 2 are linked by X and Y axes
> - sub1, sub 2 and sub5 are linked by X axes
> - sub1 and sub 3 are linked by Y axes
> - sub2 and sub 4 are linked by Y axes.
>
> Any help would be great, I am stopped by this problem since many days.
> Thank you!

Through what mechanism are the axes being altered such that you need them to
update together? If it is through zooming, then create zoom mode objects and
use post-action callbacks to update the axis limits of the related axes.
From: Andy on
> Through what mechanism are the axes being altered such that you need them to
> update together? If it is through zooming, then create zoom mode objects and
> use post-action callbacks to update the axis limits of the related axes.

But if you wanted to do other data exploration, you would have to create other objects and adjust their callbacks as well. It's much simpler to remove the safeguards from linkaxes.
From: Camille Couzi on
Thank you andy!!! It works ok!!! :-)
 | 
Pages: 1
Prev: mnrfit
Next: plotting two matrices