필터 지우기
필터 지우기

Why does the signature of my method change at runtime?

조회 수: 1 (최근 30일)
Matthew Drummond-Stoyles
Matthew Drummond-Stoyles 2020년 5월 5일
댓글: Matthew Drummond-Stoyles 2020년 5월 6일
I have a class (made in App Designer) with a method that takes two arguments:
function updateSpeed(app, block)
end
This function is used inside a callback that is used in an event listener listening for a block's 'PostOutputs':
listener = add_exec_event_listener(block_name, 'PostOutputs', ...
@(block,event) updateSpeed(app,block));
With this code I get a 'Too many input arguments' error. However, the code runs fine if I change it to:
listener = add_exec_event_listener(block_name, 'PostOutputs', ...
@(block,event) updateSpeed(app));
If I change the method to only take one argument, and only give it one, I get the 'Too many input arguments' again. It seems that for some reason the method signature is changed to only accept one argument. I have also tried changing the method name to something obscure so I know there's not more than one method of that name.
I need to access the 'block' parameter inside 'updateSpeed', so this doesn't work. I know class methods can have more than one parameter from this page:
Why is this happening?
  댓글 수: 4
Tommy
Tommy 2020년 5월 5일
편집: Tommy 2020년 5월 5일
Just after taking a quick look, I'll point out that you can either reference your function with
@(block, event) app.updateSpeed(block)
or
@(block, event) updateSpeed(app, block)
but not
@(block, event) app.updateSpeed(app, block)
In your question, you used the second syntax, but in the file you uploaded, you use the third. Just to verify, do you still get an error if you change it to the first or second syntax?
(edit) copied to an answer, at least for now
Ameer Hamza
Ameer Hamza 2020년 5월 5일
Yes, Tommy's analysis is correct. The way you wrote it in the question caused confusion. I suggest Tommy add this as an answer so that It can be accepted and be useful for anyone else coming to this thread.

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

채택된 답변

Tommy
Tommy 2020년 5월 5일
편집: Tommy 2020년 5월 5일
You can either reference your function with
@(block, event) app.updateSpeed(block)
or
@(block, event) updateSpeed(app, block)
but not
@(block, event) app.updateSpeed(app, block)
In your question, you used the second syntax, but in the file you uploaded, you use the third. Do you still get an error if you change it to the first or second syntax?
  댓글 수: 6
Tommy
Tommy 2020년 5월 6일
Ah! Thank you very much for correcting that - I reread the note here and realized it doesn't say anything about the order!
Matthew Drummond-Stoyles
Matthew Drummond-Stoyles 2020년 5월 6일
You are correct about the 'StartFcn' requiring an expression and it being evaluated in the base workspace. That was the topic of my other question and it seems the only workaround is to use a global variable for the app instance. Your suggestion about requesting output would also work but I am not sure if that would work if I ran the app through the app designer window or when creating an executable.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by