App Designer - How do I pass a structure or array from one app to another?

I'm developing an app to process laboratory test data that will use several auxilary apps for different stages of the processing. I initially load the data file into the main app, apply some corrections/calibrations, and store it in a public structure within the main app. I want to pass that structure to a secondary app for more analysis.
I've seen many examples of passing a single value from one app to another, e.g., values from an edit field. I've used that coding approach in other places in my app and it works fine. I'm not able to find any examples of passing arrays or structures between apps. When I try to use the same approach to pass a structure, I'm getting error messages like:
Unrecognized method, property, or field 'structure' for class 'main'.
Does passing a structure work the same way or am I missing something?

 Akzeptierte Antwort

Kevin Holly
Kevin Holly am 14 Feb. 2022
The link below demostrates how to communicate between apps when using app designer.

9 Kommentare

Kevin, thank you for the reply. I had read through this section previously and was still not understanding. In the link there is the following code:
function ButtonPushed(app,event)
updateplot(app.CallingApp,app.EditField.Value,app.DropDown.Value);
end
I am able to use code similar to this to pass individual values. My problem is with passing data that are not associated with app elements. For example, instead of passing the value of an edit field (app.EditField.Value above), I want to pass a public structure containing a 6x10000 matrix.
My code is shown below,
function CaculateCcMenuSelected(app, event)
exportdata(app.CallingApp, app.data)
end
where app.data is the public data structure. I am getting the error message "Unrecognized function or variable 'app.data'."
Please let me know if you have any suggestions or if my explanation of the issue is unclear.
Have you defined data as a property as such?
properties (Access = public)
data
end
I have data defined as:
properties (Access = public)
data = struct(); % Description
end
because data is a structure that is shared and populated within the main app. Do I need to create a separate property for passing to another app?
You will need to define the other app as a property.
properties (Access = public)
data = struct(); % Description
CallingApp % Main app object
end
Is data first defined in the main app?
I want to make sure the data isn't stored in app.CallingApp.data for instance.
I believe the data is first defined in the main app. I probably haven't provided enough information in my previous posts. I've pasted all of the pertinent code from both the main app (CRSMain) and the auxillary app (CalcCc) below.
Code in CRSMain (I want to send the data structure app.data from here to CalcCc).
properties (Access = private)
CalcCc %Calculate Cc auxillary app
end
properties (Access = public)
data = struct(); % public data structure defined in CRSMain to store imported data
end
The CalcCc auxillary app is opened from the menu selection shown below, and app.data is what I want to send to CalcCc.
function CaculateCcMenuSelected(app, event)
app.CalcCc=CalcCc(app,app.data);
end
Code in the CalcCc auxillary app (I want to receive app.data from CRSMain)
properties (Access = private)
callingapp% Description
end
properties (Access = public)
data = struct();
end
Startup function in CalcCc
function startupFcn(app, CRSMain, datafromCRSMain)
app.callingapp = CRSMain;
app.data = datafromCRSMain;
end
When I activate CaculateCcMenuSelected in CRSMain, I get the following error.
Error using CalcCc/startupFcn (line 28)
Unrecognized property 'data' for class 'CalcCc'.
Error in CalcCc (line 90)
runStartupFcn(app, @(app)startupFcn(app, varargin{:}))
Error in CRSMain/CaculateCcMenuSelected (line 362)
app.CalcCc=CalcCc(app,app.data);
Error using matlab.ui.internal.controller.WebMenuController/fireActionEvent (line 67)
Error while evaluating Menu Callback.
Do the following and let me know if it works:
CRSMain
properties (Access = private)
CalcCc % Calculate Cc auxillary app
end
properties (Access = public)
data = struct(); % public data structure defined in CRSMain to store imported data
end
function CaculateCcMenuSelected(app, event)
app.CalcCc=CalcCc(app,app.data);
end
CalcCc
properties (Access = private)
callingapp % Description
end
function startupFcn(app, CRSMain)
app.callingapp = CRSMain;
app.callingapp.data % This should display your data in your command window. You can access your data with app.callingapp.data
end
I updated to what you have above and am now getting the error:
Error using CalcCc (line 90)
Too many input arguments.
Error in CRSMain/CaculateCcMenuSelected (line 370)
app.CalcCc=CalcCc(app,app.data);
Error using matlab.ui.internal.controller.WebMenuController/fireActionEvent (line 67)
Error while evaluating Menu Callback.
I meant to remove the app.data. sorry about that.
function CaculateCcMenuSelected(app, event)
app.CalcCc=CalcCc(app);
end
That worked! Thanks Kevin - I appreciate your help!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

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

Gefragt:

am 14 Feb. 2022

Bearbeitet:

am 15 Feb. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by