Why "timerfcn" do not recognize handles

3 次查看(过去 30 天)
I am using "timerfcn" to simulate a plot. code was working fine. But when i used it in gui, timerfcn stopped recognizing the defined variables; handles. how to pass handles form callback functions to timerfcn. I have labeled screen shorts to explain the error.
I defined handles L1,L2,L3,L4 and th in OpeningFcn to plot initial static graph
Then i used timerfcn inside Callback function of a "checkbox" labeled as "Animate" . It can be observed that handles are working fine outside timerfcn but are not recognized by the function.
What is recommended way of doing it? Is there any way to export these handles to base workspace so that timer function can work?
  4 个评论
Sean de Wolski
Sean de Wolski 2021-12-15
That just means the chosen architecture is bad. With component containers now allowing you to build modular components there's no reason an app ever needs to get that large. Pair that with model-view-control or a modified-model-view-control that does view/control in app designer and a data model class these problems are completely avoidable for large scale apps.
Walter Roberson
Walter Roberson 2021-12-15
About 3 months ago, a number of us met with one of the managers for App Designer. The manager said nothing about modular components as being a potential cure for the performance problems that we were talking about.
The manager also had no resolution for the problem that the IDE for code that is outside of App Designer (such as a "data model class") is in a different window than the IDE for App Designer, making it a challenge to split the design in the way you are recommending.
Telling people that they have to refactor their design into smaller pieces to get around the fact that 5000 lines of code can take up to 20 minutes just to scroll is not an acceptable solution to the performance problems of App Designer.
There are two separate but related issues here:
  1. Performance of code built with App Designer. Mathworks has put a lot of effort into that, and in particular says that R2021b is significantly improved
  2. Performance and usability of App Designer itself for creating code. This continues to be a challenge.
Users have been posting saying that their team of programmers spent multiple months converting their projects to App Designer, and are finding that they have to convert back because App Designer is, in their experience, not workable for medium or large sized projects.
As far as I am concerned, App Designer is still only suitable for Prototype stage. That does not mean it does not have value, but blanket recommendations of "really should" switch to App Designer are rather premature in my opinion.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2021-12-14
You are using a character vector as the timer function. When you use a character vector as a callback, then the character vector is evaluated in the base workspace. The base workspace does not have a variable named handles in it.
You should be switching to using an anonymous function as the callback.
Note: timer callbacks are not expected to return values. If you did code properly to be able to find the handles within a character vector callback, then Yes the base workspace A and th variable would be changed by the callback. That is not good design, though. If you really need to assign into the base workspace use assignin(). But consider other ways of storing values; http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by