Problems including a new KeyPressFcn to call a function in axdrag file
2 ビュー (過去 30 日間)
古いコメントを表示
Hi all,
I am using this file (axdrag) with my plot. I included new lines to call a function when the key 'g' is pressed but it does not work. There is not error, so the coding is correct, but somewhat these new lines are not doing the task in the plot.
Here is part of the code of axdrag
function axdrag(action)
if nargin < 1
action = 'initialize';
end
% Use these variables to change the zoom and pan amounts
zoomFactor = 0.9;
panFactor = 0.02;
%Code continues
switch action
case 'initialize'
set(gca,'ButtonDownFcn','axdrag start')
set(gcf,'KeyPressFcn','axdrag keypress')
set(gcf,'DoubleBuffer','on')
case 'start'
set(gcbf,'Units','pixel');
set(gca,'Units','pixel');
set(gcbf,'WindowButtonMotionFcn','axdrag move')
set(gcbf,'WindowButtonUpFcn','axdrag stop')
currentPoint = get(gcbf,'CurrentPoint');
x0 = currentPoint;
axdrag move
case 'move'
currentPoint = get(gcbf,'CurrentPoint');
dx = currentPoint - x0;
x0 = currentPoint;
ap = get(gca,'Position');
xLim = get(gca,'XLim');
yLim = get(gca,'YLim');
set(gca,'XLim',xLim-(diff(xLim)*dx(1)/ap(3)), ...
'YLim',yLim-(diff(yLim)*dx(2)/ap(4)));
case 'stop'
set(gcbf,'WindowButtonMotionFcn','')
set(gcbf,'WindowButtonUpFcn','')
set(gcbf,'Units','normalized');
set(gca,'Units','normalized');
case 'keypress'
currChar = get(gcbf,'CurrentCharacter');
if isempty(currChar)
return
end
if currChar=='a'
axis auto
elseif currChar=='e'
axis equal
% Code continues
end
end
end
Then, I included this line, but it is doing nothing
elseif currChar=='g'
myginput(1)
I expected to enable the selection of one point in my plot. But as I said, nothing is running.
Also, I tried with this (simpler task), but again, it does not work.
elseif currChar=='g'
zoom on
The way I call the function in the Command Window:
plot(x,y)
axdrag
How can I call a function that works in the plot by pressing a key?
Thanks,
Jose
7 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!