(App Designer) Callback for an ROI event does not work

조회 수: 6 (최근 30일)
Marek Svoboda
Marek Svoboda 2019년 8월 19일
댓글: Marek Svoboda 2019년 8월 25일
I have spent a lot of time trying to figure this out, so now is time to ask for help -
In App Designer, I have been trying to set up a callback triggered by changing a position of an ROI line in a (standard, not UI) axes object
function startupFcn(app)
app.ax = axes(app.Panel, 'Title', [], 'XLabel', [], 'YLabel', [], 'Color', 'none','YColor', 'none', 'Xlim', [0 1.5], 'YTick', [], 'XTick', [0 0.5 1 1.5], 'TickDir', 'both', 'TickLength', [0.03 0.035], 'XMinorTick', 'on', 'Units', 'pixels','Position', [8 30 284 0]);
disableDefaultInteractivity(app.ax);
app.ax.Toolbar.Visible = 'off';
app.line1 = drawline(app.ax,'Position',[app.RMP_t1 0; app.RMP_t2 0]);
addlistener(app.line1, 'Position', 'ROIMoved', @line1Moved);
drawnow;
app.UIFigure.WindowState = 'maximized';
end
However, I get the following error:
Error using images.roi.Line/addlistener
Event 'ROIMoved' is not defined for class 'images.roi.Line'.
According to the documentation on images.roi.Line class, this should be a valid event name. By the way, when I remove the 'Position' argument, the app runs without errors but the callback (@line1Moved) doesn't do anything.
  댓글 수: 1
Jyotsna Talluri
Jyotsna Talluri 2019년 8월 22일
The error is due to 'Position' argument and its not due to 'ROIMoved' as addlistener creates listener for given event triggered by callback function on the object.It cannot take 'Position' as argument.
If your function 'line1Moved' is correct then that should work fine.Can your provide your 'line1Moved' function so that I can check

댓글을 달려면 로그인하십시오.

채택된 답변

Marek Svoboda
Marek Svoboda 2019년 8월 22일
Thank you @Joytsna for your answer!
I actually figured it out last night - and you are correct, the 'Position' shouldn't be there. Here is the correct code for the addistener() that now works in my app (adapted from Marc McLean's answer):
addlistener(app.l1, 'MovingROI', @(varargin)l1Moving(app, app.l1));
It does not work without the "(varargin)" and "(app, app.l1)" pieces, which I still quite don't understand. I know that "varargin" allows a function to take in a variable number of inputs, but I'm not sure what exactly it does here, when placed before the function handle.
  댓글 수: 2
Jyotsna Talluri
Jyotsna Talluri 2019년 8월 25일
That implies 'varargin' is argument to the function handle,which means it takes any number of inputs.The function 'l1Moving' can be called with any numer of input arguments
Marek Svoboda
Marek Svoboda 2019년 8월 25일
Thank you for the explanation!
I still don't understand, however, why the function doesn't work without the "(varargin)" part even when the input arguments correspond to the definition of the function called.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by