📄 panfcn.m
字号:
else
np = get(panneraxes,'currentpoint'); % new point
end
np = np(1,1:2);
if any(isnan(np)), np = p; end
oxlim = xlim;
oylim = ylim;
if directflag % drag line in main axes
if logscale(1)
xlim = 10.^ (log10(oxlim) - log10(np(1)/p(1)));
else
xlim = oxlim - (np(1)-p(1));
end
if logscale(2)
ylim = 10.^ (log10(oylim) - log10(np(2)/p(2)));
else
ylim = oylim - (np(2)-p(2));
end
else % drag panner patch
if logscale(1)
xlim = 10.^ (log10(oxlim) + log10(np(1)/p(1)));
else
xlim = oxlim + (np(1)-p(1));
end
if logscale(2)
ylim = 10.^ (log10(oylim) + log10(np(2)/p(2)));
else
ylim = oylim + (np(2)-p(2));
end
end
if ~isempty(bounds)
xlim1 = inbounds(xlim,bounds.xlim,logscale(1));
ylim1 = inbounds(ylim,bounds.ylim,logscale(2));
if ~isequal(xlim,xlim1)
if directflag
if logscale(1)
np(1) = 10.^( log10(np(1)) - log10(xlim1(1)/xlim(1)) );
else
np(1) = np(1)-(xlim1(1)-xlim(1));
end
else
if logscale(1)
np(1) = 10.^( log10(np(1)) + log10(xlim1(1)/xlim(1)) );
else
np(1) = np(1)+(xlim1(1)-xlim(1));
end
end
xlim = xlim1;
end
if ~isequal(ylim,ylim1)
if directflag
if logscale(2)
np(2) = 10.^( log10(np(2)) - log10(ylim1(1)/ylim(1)) );
else
np(2) = np(2)-(ylim1(1)-ylim(1));
end
else
if logscale(1)
np(2) = 10.^( log10(np(2)) + log10(ylim1(1)/ylim(1)) );
else
np(2) = np(2)+(ylim1(1)-ylim(1));
end
end
ylim = ylim1;
end
end
function saveCallbacks = installCallbacks(h,fig,callbackList,valueList)
% installCallbacks
% inputs:
% h - handle of object which will be changed by callbacks
% fig - handle of figure
% callbackList - list of figure callbacks in cell array
% elements are e.g., 'windowbuttonmotionfcn'
% valueList - same length as callbackList - cell array containing
% values (string or numeric) for h's userdata
% outputs:
% saveCallbacks - cellarray of what the callbacks were before
saveCallbacks = cell(1,length(callbackList));
for i=1:length(callbackList)
if isstr(valueList{i})
vstr = ['''' valueList{i} ''''];
else
vstr = num2str(valueList{i});
end
if 0, % if problems with fig not being gcf, set this to 1
figstr = ['hex2num(''' sprintf('%bx',h) ''')'];
else
figstr = 'gcf';
end
str = ['set(findall(' figstr ',' ...
'''tag'',''' get(h,'tag') '''),''userdata'',' ...
vstr ')'];
saveCallbacks{i} = get(fig,callbackList{i});
set(fig,callbackList{i},str)
end
%
function event = waitForNextEvent(h)
% waitForNextEvent
set(h,'userdata',0)
waitfor(h,'userdata')
event = get(h,'userdata');
function switchToBorderAxes(ax,borderaxes)
% This function hides the main axes and shows the border axes.
% IF borderaxes is NOT EMPTY:
% It hides the main axes by setting its x and ycolor to the
% color of the axes, instead of turning the mainaxes invisible -
% this is because if we just set visible to off, any lines
% in background erasemode would erase in the FIGURE's background
% color, not the axes' (and that would be bad).
% ELSE
% Just turns off the axes ticks.
if ~isempty(borderaxes)
ax_color = get(ax,'color');
if isstr(ax_color)
% use figure's color in case axes's color is 'none'
ax_color = get(get(ax,'parent'),'color');
end
set(ax,'xcolor',ax_color,'ycolor',ax_color)
set(get(ax,'xlabel'),'color',get(borderaxes,'xcolor'))
set(get(ax,'ylabel'),'color',get(borderaxes,'ycolor'))
set(borderaxes,'visible','on')
end
set(ax,'xtick',[],'ytick',[])
function switchToMainAxes(ax,borderaxes)
% This function hides the border axes and shows the main axes.
% It undoes what switchToBorderAxes does.
% Assumes xcolor and ycolor of ax should be the same as those of borderaxes
if ~isempty(borderaxes)
set(ax,'xcolor',get(borderaxes,'xcolor'),...
'ycolor',get(borderaxes,'ycolor'))
set(borderaxes,'visible','off')
end
set(ax,'xtickmode','auto','ytickmode','auto')
function doDynamicDrag(xlim,ylim,actual_xlim,actual_ylim,data,...
transform)
% needed by setDataWithTransform:
xl = [xlim(:)' actual_xlim];
yl = [ylim(:)' actual_ylim];
hh=[]; xx={}; yy={};
for i=1:length(data)
if data(i).Fs>0
% translate interval to integer indices
xlim1 = xlim*data(i).Fs + (1-data(i).Fs*data(i).t0);
xlim1 = [floor(xlim1(1)) ceil(xlim1(2))];
ind = max(1,xlim1(1)):min(xlim1(2),size(data(i).data,1));
if ~isempty(ind)
if ind(1) == 0, ind(1) = []; end
x = (ind-1)/data(i).Fs + data(i).t0;
for j = 1:length(data(i).h)
y = data(i).data(ind,j);
if ~isempty(transform)
y = feval(transform,y);
end
hh = [hh; data(i).h(j)];
xx = {xx{:} x};
yy = {yy{:} y};
end
else
hh = [hh; data(i).h(:)];
for j = 1:length(data(i).h)
xx = {xx{:} []};
yy = {yy{:} []};
end
end
else
for j = 1:length(data(i).h)
x = data(i).xdata(:,j);
y = data(i).data(:,j);
if ~isempty(transform)
y = feval(transform,y);
end
hh = [hh; data(i).h(j)];
xx = {xx{:} x};
yy = {yy{:} y};
end
end
end
% wait until end to set data, so all lines are erased, and THEN
% redrawn. This prevents background erasures from erasing other
% previously drawn lines.
setDataWithTransform(hh,xl,yl,xx',yy')
function setDataWithTransform(h,xlim,ylim,xd,yd)
%setDataWithTransform Set xdata and ydata of lines transforming from one
% set of limits to another.
% Inputs:
% h - vector of line handles
% xlim, ylim - limits of mainaxes
% if xlim and ylim are 4 elements long, uses the 3rd and 4th
% elements as the interval in which to map the data.
% xd - vector or cell array. Each element of the cell
% will get mapped from xlim to [0 1] or xlim(3:4)
% yd - vector or cell array. Each element of the cell
% will get mapped from ylim to [0 1] or ylim(3:4)
if length(xlim)<=2
xslope = 1/diff(xlim);
xintercept = -xlim(1)*xslope;
else
xslope = (xlim(4)-xlim(3))/(xlim(2)-xlim(1));
xintercept = xlim(3)-xlim(1)*xslope;
end
if length(ylim)<=2
yslope = 1/diff(ylim);
yintercept = -ylim(1)*yslope;
else
yslope = (ylim(4)-ylim(3))/(ylim(2)-ylim(1));
yintercept = ylim(3)-ylim(1)*yslope;
end
if ~iscell(xd)
xd = {xd};
end
if ~iscell(yd)
yd = {yd};
end
for j=1:length(h)
xd{j} = xslope*xd{j}+xintercept;
yd{j} = yslope*yd{j}+yintercept;
end
set(h,{'xdata'},xd,{'ydata'},yd)
function setpdata(panpatch,xlim,ylim)
%setpdata - set x and ydata of patch object to rectangle specified by
% xlim and ylim input
set(panpatch,'xdata',[xlim(1) xlim(2) xlim(2) xlim(1) xlim(1)], ...
'ydata',[ylim(1) ylim(1) ylim(2) ylim(2) ylim(1)]) % thumb patch
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -