필터 지우기
필터 지우기

addlistener syntax not recognized in R2014b

조회 수: 2 (최근 30일)
Matt J
Matt J 2014년 11월 18일
답변: Ian Noell 2014년 11월 27일
I've just installed R2014b, and have been testing various pieces of my code library fearful of what the new Graphics System is going to break. One routine I have relies on a File Exchange submission with the following local function,
function localSetupPositionListener(hFig,imAxes)
% helper function to sets up listeners for resizing, so we can detect if
% we would need to change the fontsize
PostPositionListener = handle.listener(hFig,'ResizeEvent',...
{@localPostPositionListener,imAxes});
setappdata(hFig,'KenFigResizeListeners',PostPositionListener);
end
After running the MATLAB Graphics Updater app, this local function gets converted to the following,
function localSetupPositionListener(hFig,imAxes)
% helper function to sets up listeners for resizing, so we can detect if
% we would need to change the fontsize
PostPositionListener = addlistener(hFig,'SizeChanged',...
{@localPostPositionListener,imAxes});
setappdata(hFig,'KenFigResizeListeners',PostPositionListener);
end
But when I run the code, the line that has changed throws an error,
No method 'addlistener' with matching signature found for class 'matlab.ui.Figure'.
Error in TextZoomable>localSetupPositionListener (line 80)
PostPositionListener = addlistener(hFig,'SizeChanged',...
Error in TextZoomable (line 58)
localSetupPositionListener(hFig,hAx);
Any ideas why the error occurs and, as importantly, why the app doesn't catch it (so I can be on the lookout for other instances where it may fail)?
  댓글 수: 2
Adam
Adam 2014년 11월 18일
Silly question: have you tried just reverting it to the previous if it was changed by the updater app?
I am on R2014a at home and addlistener does not work with that syntax there, but the top version does (well, I can type the listener line without a syntax error, I haven't tried hooking it up somewhere live.
Matt J
Matt J 2014년 11월 18일
Adam, yes I verified that the original version does not work in R2014b.

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

채택된 답변

matt dash
matt dash 2014년 11월 18일
Addlistener doesn't let you use the cell array syntax on the 3rd argument the way every other callback function works. You must specify a "bare" function handle for the 3rd argument.
  댓글 수: 1
Matt J
Matt J 2014년 11월 18일
편집: Matt J 2014년 11월 18일
Thanks.
You must specify a "bare" function handle for the 3rd argument.
I think you mean it needs to be changed as follows?
PostPositionListener = addlistener(hFig,'SizeChanged',...
@(o,e) localPostPositionListener(o,e,imAxes) );

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

추가 답변 (2개)

Ian Noell
Ian Noell 2014년 11월 27일
As matt dash said, addlistener needs a function handle or an anonymous function for the callback. The cell array syntax was supported by handle.listener (although undocumented) but is not for event.listener/addlistener.
I have added a note to the message in the MATLAB Graphics Updater app and updated the submission. You will need to make manual changes to your code to update the callback.

Guillaume
Guillaume 2014년 11월 18일
Which version are you upgrading from?
Your old code gives me the same error in R2013b. The problem in either version is that addlistener / event.listener expects a function handle for the third argument, whereas you're passing a cell array, the purpose of which I'm not sure.
  댓글 수: 1
Matt J
Matt J 2014년 11월 18일
편집: Matt J 2014년 11월 19일
Can't account for that, I'm afraid. The original version works fine for me in R2013b.

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

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by