Issue with presetting the data assigned to a variable in MATLAB App Designer

1 Ansicht (letzte 30 Tage)
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.
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)
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.

Antworten (1)

Yu Lu
Yu Lu am 26 Feb. 2021
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 Kommentare
Yu Lu
Yu Lu am 27 Feb. 2021
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.
SRIRAM NTIHIN GOPAL LANKA
SRIRAM NTIHIN GOPAL LANKA am 2 Mär. 2021
I still see the same error. Any help would be greatly appreciated.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by