Why does the signature of my method change at runtime?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Matthew Drummond-Stoyles
el 5 de Mayo de 2020
Comentada: Matthew Drummond-Stoyles
el 6 de Mayo de 2020
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 comentarios
Tommy
el 5 de Mayo de 2020
Editada: Tommy
el 5 de Mayo de 2020
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
el 5 de Mayo de 2020
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.
Respuesta aceptada
Tommy
el 5 de Mayo de 2020
Editada: Tommy
el 5 de Mayo de 2020
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Event Functions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!