How create cursor bar in UIAxes of App Designer?

8 ビュー (過去 30 日間)
galaxy
galaxy 2022 年 9 月 6 日
コメント済み: galaxy 2022 年 9 月 8 日
Hi all,
I used cursorbar tool for creating cursor bar in figure.
But I could not use it in UIAxes. Do anyone know, please tell me.
Thank you

回答 (1 件)

chrisw23
chrisw23 2022 年 9 月 7 日
classdef Cursor < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
figCursorExample matlab.ui.Figure
axCursor matlab.ui.control.UIAxes
end
properties (Access = private)
cursorLine
sinLine
lockCursorLine
intersecPoint
end
methods (Access = private)
function MouseMoveCallback(app,~,~)
% check if mouse pointer within axes area
x2 = app.axCursor.CurrentPoint(1,1);
y2 = app.axCursor.CurrentPoint(1,2);
x2min = min(app.axCursor.XLim);
x2max = max(app.axCursor.XLim);
y2min = min(app.axCursor.YLim);
y2max = max(app.axCursor.YLim);
if (x2 >= x2min && x2 <= x2max) && (y2 >= y2min && y2 <= y2max)
if app.lockCursorLine
app.cursorLine.XData = [x2 x2];
end
end
end
function ReleaseLineLockCallback(app,~,~)
if app.lockCursorLine
x = app.cursorLine.XData(1);
app.intersecPoint.Position(1:2) = [x,sin(x)];
end
app.lockCursorLine = false;
end
function GrabCursorCallback(app,~,~)
app.lockCursorLine = true;
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.axCursor.XLim = [0 2*pi];
app.axCursor.YLim = [-2 2];
x = [0:0.1:2*pi];
y = sin(x);
app.sinLine = plot(app.axCursor,x,y);
app.cursorLine = line(app.axCursor,[pi pi],[-2 2]);
dataCursorManager = datacursormode(app.figCursorExample);
app.intersecPoint = dataCursorManager.createDatatip(app.sinLine);
app.intersecPoint.Tag = "intersecPoint";
app.intersecPoint.DataTipStyle = 'MarkerOnly';
drawnow
app.intersecPoint.Position = [app.cursorLine.XData(1) sin(app.cursorLine.XData(1)) 0];
app.figCursorExample.WindowButtonMotionFcn = @app.MouseMoveCallback;
app.figCursorExample.WindowButtonUpFcn = @app.ReleaseLineLockCallback;
app.cursorLine.ButtonDownFcn = @app.GrabCursorCallback;
end
end
% Component initialization
...
% App creation and deletion
...
This is just an example and adapted to a sine wfm but maybe it helps to figure out how it could work for you.
Here you have to hit the cursor line exactly to grab it for moving, but you can use markers too.
  3 件のコメント
galaxy
galaxy 2022 年 9 月 8 日
Anyway thank you so much.
I modified and I created what I want.
Best regards

サインインしてコメントする。

カテゴリ

Find more on Migrate GUIDE Apps in Help Center and File Exchange

製品


リリース

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by