Rank: 162736 based on 0 downloads (last 30 days) and 0 file submitted
photo

Tobias

E-mail

Personal Profile:
Professional Interests:

 

Watch this Author's files

 

Comments and Ratings by Tobias
Updated File Comments Rating
29 Apr 2013 addaxis Add multiple y-axes to plots. zoomable with zoom modification. Author: Harry Lee

Great function!
For those of you who can not figure out how to make the zooming and panning working, here is a solution:

1. Open the addaxis.m and find these lines: "% plot in new axis to get the automatically generated ylimits
hplt = plot(varargin{:});"

2. Add the following code after "hplt = plot(varargin{:});" :
h_new = zoom;
set(h_new,'ActionPostCallback',@postcallbackzoom);
set(h_new,'ActionPreCallback',@precallbackzoom);
set(h_new,'Enable','on');
set(h_new,'Enable','off');
h_new=pan;
set(h_new,'ActionPostCallback',@postcallbackpan);
set(h_new,'ActionPreCallback',@precallbackpan);
set(h_new,'Enable','on');
set(h_new,'Enable','off');

3. Goto the end of 'addaxis.m' and add the followong code:

function precallbackzoom(obj,evd)
old(1:2) = get(evd.Axes,'YLim');
old(3) = evd.Axes;
ax = findall(obj,'type','axes');
ax = ax(ax~=evd.Axes);
leg = findall(obj,'Tag','legend');
if(~isempty(leg))
ax = ax(ax~=findall(obj,'Tag','legend'));
end
for i=1:length(ax)
old(i+1,1:2)=get(ax(i),'YLim');
old(i+1,3)=ax(i);
end
setappdata(obj,'OldAxes',old);

function postcallbackzoom(obj,evd)
old = getappdata(obj,'OldAxes');
new(1:2) = get(evd.Axes,'YLim');
d=(old(1,2)-old(1,1));
d1=(new(1)-old(1,1))/d;
d2=(new(2)-old(1,2))/d;
s=size(old);
for i=2:s(1)
d=old(i,2)-old(i,1);
set(old(i,3),'YLim',[ (old(i,1))+d*d1 , (old(i,2))+d*d2]);
end
function postcallbackpan(obj,evd)
set(obj,'WindowButtonMotionFcn','');

function precallbackpan(obj,evd)
ax = findall(obj,'type','axes');
ax = ax(ax~=evd.Axes);
leg = findall(obj,'Tag','legend');
if(~isempty(leg))
ax = ax(ax~=findall(obj,'Tag','legend'));
end
OldY=[get(gca,'YLim'),ax'];
set(obj,'WindowButtonMotionFcn',{@CallbackPan,obj});
setappdata(obj,'OldY',OldY);

function CallbackPan(hObject, eventdata, handles)
old = getappdata(hObject,'OldY');
new(1:2) = get(gca,'YLim');
d=(new(1)-old(1))/(new(2)-new(1));
for i=3:length(old)
d1 = get(old(i),'YLim');
d1_= d1(2)-d1(1);
set(old(i),'YLim',d1+d*d1_);
end
old(1:2)=new;
setappdata(hObject,'OldY',old);

4. That's it. Save your addaxis.m and enjoy zooming and panning. By the way you don't have the use the new zoom-functions (zoom modifications for R11.1 and R14SP2) provided with this function.
Tested on Matlab 2012b.

Contact us