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

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.

Answers (1)

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 Comments

Hi
thank you for your response. Using your suggestions I tried to run the following code upon clicking on a reset button after I modify the app.PIN parameters:
app1=example; % Obtaining the app handle and example is the name of the matlab file
h_fig = findall(0,'Name','example');
h_app = h_fig.RunningAppInstance;
app2 = example;
app2.UITable.Data = app1.UITable.Data;
I see an error which says
Unrecognized method, property, or field 'RunningAppInstance' for class 'matlab.graphics.GraphicsPlaceholder'.
It would be great if you help me fix this. Also, if I am doing something wrong please let me know. Thank you and hoping to hear from you soon.
Hi
Sorry for the confusing, the name used in this command
h_fig = findall(0,'Name','example');
is the name show up on your app's top left corner next to the matlab icon, by default it is 'MATLAB App'.
Also you may use
h_fig = findall(0,'Type','figure');
to find the figure handle.
Thanks!
Thank you. I have modified the code as follows :
%% example is the name of the App
app1=example;
h_fig = findall(0,'Type','Figure');
h_app = h_fig.RunningAppInstance;
app2 = example;
app2.UITable.Data = app1.UITable.Data;
I still see the same error as :
Unrecognized method, property, or field 'RunningAppInstance' for class 'matlab.ui.Figure'.
Hoping to hear from you.
In the command
h_fig = findall(0,'Type','Figure');
'Figurre' should be all in lower case as
h_fig = findall(0,'Name','figure');
Sorry for the inconfient, I guess the issue maybe there are other figures opened. In this case you may use
h_fig = findall(0,'Name','MATLAB App');
Here the name 'MATLAB App' is the figure title on the top left corner of your running app.
There is another anwser talking about how to get app handle on running apps you may refer to.
I tried everything as you suggested but still see the same error.
In this case, can you share the version of your matlab, you can using the
version
command to get the version info.
Also the output for
h_fig = findall(0,'Name','MATLAB App')
will be useful to debug the issue here.
Thanks!
'9.7.0.1247435 (R2019b) Update 2'
h_fig =
0×0 empty GraphicsPlaceholder array.
I see the same output for h_fig = findall(0,'Name','UI Figure')
as UI Figure is the name beside the MATLAB icon.
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.
I still see the same error. Any help would be greatly appreciated.

Sign in to comment.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!