Issue with presetting the data assigned to a variable in MATLAB App Designer
3 次查看(过去 30 天)
显示 更早的评论
Hello
I hope you are doing good. So I have defined some variables as shown in the figure. These variables are called in different functions in a MATLAB App Designer program.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/530434/image.png)
Upon clicking a button, app.PIN is assigned as shown in the picture below, and the rest of the code is executed accordingly.(Start is given as 0 Stop is given as 30 Step is given as 1 by the user)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/530439/image.png)
Now upon clicking a different button I am trying to assign a different value to app.PIN (Start as -30 Stop as 30 and Step of 1) and I am getting an error which says:
Unable to perform assignment because the size of the left side is 31-by-1 and the size of the right side is 1-by-61.
I think that makes sense and I feel that some of the variables must be preset before assigning a new value. I do not want to use different variables as app.PIN is used in a different function to plot the graphs. I am not interested in running the program all over again because some of the tables contain some data and i do not want to reset anything. Any help to reset/preset the current value of app.PIN would be greatly appreciated.
Thank you.
0 个评论
回答(1 个)
Yu Lu
2021-2-26
Hello,
From my understanding you want to reset/preset a private property in a running app. Unfortunately it is not officially supported to modify the apps private properties outside the app class, however we do have 2 possible workarounds for your case.
For both workarounds you needs to get the handle of the running app first. There is an article talking about how to get the running app handle here.
Workaround 1:
You still need to run the program again but, you can save a lot of time by transfer table data from old app to new app.
1. Keep your current running app open, get the app handle as app1.
h_fig = findall(0,'Name','<Your_App_Title>');
h_app = h_fig.RunningAppInstance;
2. Update your app code to reset/preset the properties before assigning new value (There are different ways: You may add a reset button and do the resets in the button callback, or you can set the access of this properties to public, then they can be access and modified in run time in command line.).
3. Run the updated app as
app2 = YourAPPName;
Then your can transfer the component status and data from app1 to app2 to preserve the running states. eg
app2.UITable.Data = app1.UITable.Data;
Workaround 2:
There is an undocumented way to access and modify private properties, but please be aware it is not supported officially by the product, and it is not guaranteed to be working on your case.
Hope these two workarounds can help with your question.
11 个评论
Yu Lu
2021-2-27
I have tried the same verison of matlab, the workflow should work on this version.
What I can suggest now is to use
allComponents = findall(0)
The output should be like this
allComponents =
5×1 graphics array:
Root
Figure (UI Figure)
GridLayout
Panel
Panel
Then you can use the index of figure in the array 'allComponents' like this
h_fig - allComponents(2)
To access the figure handle.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!