Passing variables between GUI's and invalid object or handle

Hi, I am passing variables to 2 seperate GUI's. The code is as follows
setappdata(0,"txt3",app.txt3);
setappdata(0,"N_students",app.N_students);
calling_MpPC_app = MpPC_table; % sending txt3 and N_students to MpPC_table app
waitfor(calling_MpPC_app);
app.Number_of_projs_floated_coded = getappdata(0,'Number_of_projs_floated_coded'); % getting output from MpPC_table app
app.Max_proj_allocations = getappdata(0,'Max_proj_allocations');
app.original_proj_list = app.txt3;
setappdata(0,"Max_proj_checker",[app.Number_of_projs_floated_coded(:,1) app.Max_proj_allocations]);
setappdata(0,"txt3",app.txt3)
callingapp = x_gui; % Sending Max_proj_checker and txt3 to x_gui app
waitfor(callingapp);
app.Roll_nos_GUI = getappdata(0,'Roll_nos_GUI'); % getting output from x_gui
app.Projnames_GUI = getappdata(0,'Projnames_GUI');
But when I get the output from x_gui app (last two lines). I get an error invalid object or handle. I think this is due to overwriting done by the previous setappdata command. And storing them in a root directory is as bad as declaring a global variable.
I am using App Designer to create this. But I didn't find any figure handle to specify in the setappdata command. Like In the documentation it says
f=figure
setappdata(f,"Variable name")
But I don't find any line specifying this. I tried putting x_gui instead, But the same error pops and an extra x_gui app window opens.
Any idea on how to do it.
PS: A workaround can be saving them into base and calling them again

 Réponse acceptée

The setappdata function also accepts uifigure handles, so you need to use that as input:
app=struct('self',uifigure);
%%
setappdata(app.self,'data',1)
%%
getappdata(app.self,'data')

5 commentaires

Since I have multiple figures, Can I use any string other than 'self' ?
Like
app = struct('xxx',uifigure)
setappdata(app.xxx,'data',1)
getappdata(app.xxx,'data')
Of course, but since you are already using AppDesigner, there probably is already a field with the handle to the uifigure, which is why I went for this syntax as an example. As soon as one app has the handle to the other, they can use a shared data structure.
But I didn't find any such thing like that. The only thing I find is this
PAllocationUIFigure matlab.ui.Figure
Can you elaborate more please.
AppDesigner has a class-like design philosophy.
That line looks like there is property in you GUI called PAllocationUIFigure with the data type matlab.ui.Figure, meaning that in a callback app.PAllocationUIFigure will contain the handle to the uifigure that is your GUI.
For general advice and examples for how to create a GUI, have look at this thread. I personally have little to no experience with AppDesigner, but you will find usefull doc links on that page.
Thank you. Will do it

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by