Undefined function error when passing data in multiwindow apps

4 views (last 30 days)
Hello,
I'm trying to create a multiwindow app. The way I've got it setup, is the user will make some selections on the main app, click a button, and if a certain condition is met based on their selections, a second app window will open where they will make some additional inputs. Once complete, they will click a button which will send their inputs back to the main app and resume its execution (in order to create a graph in Excel, in my case). I've followed the instructions in the MathWorks documentation for this (Create Multiwindow Apps in App Designer - MATLAB & Simulink (mathworks.com)), but I am getting an error which says "Undefined function 'addVariableUnit' for input arguments of type 'double'.", where 'addVariableUnit' is the public function in my main app, which I am calling from the second app, in order to pass over the users inputs. It seems that the second app does not recognize this function, even though I've made it public in the main app. Below is my code. I've attached the mlapp files as well, where the lines of interest in the main app are 100-106 (calling the second app), 162-174 (public function in the main app to retrieve second apps data). The second app is quite short.
Main app (createChart_App.mlapp):
methods (Access = private)
function [yTitle1] = createChartErrorChecks (app, wb_proc, A, axis)
...
%checking condition based on users selections
if yUnit == "none"
%Open second app window
app1 = enterVariableUnit;
%pause execution until window is closed
while isvalid(app1); pause(1); end
end
end
end
methods (Access = public)
%public function to pass data from second app to main app
function addVariableUnit(app, variable, unit)
%do stuff with variable and unit
...
end
end
Second app (enterVariableUnit.mlapp):
properties (Access = private)
CallingApp % Main app object
end
methods (Access = private)
% Button pushed function: EnterButton
function EnterButtonPushed(app, event)
%call main apps public function, provide it with the users inputs
addVariableUnit(app.CallingApp, app.variableUnit.Value, app.variableName.Value);
delete(app)
end
end

Accepted Answer

Reshma Nerella
Reshma Nerella on 12 Apr 2022
Hi,
In the function "createChartErrorChecks" in the main app, you need to open the dialog app by passing the main app as the argument.
Instead of
app1 = enterVariableUnit;
Use the following line of code: Create a private property "DialogApp" and pass the main app as argument.
app.DialogApp = enterVariableUnit(app);
For more information, refer to the following documentation page: Create Multiwindow Apps in App Designer
  1 Comment
Patrick Mirek
Patrick Mirek on 13 Apr 2022
Yes I was missing that, thank you! In addition, I needed to create a startup function in my dialog app to recieve this "app" argument:
% Code that executes after component creation
function startupFcn(app, mainapp)
%take the mainapp variable (from createChart_App) and assign it
%to CallingApp
app.CallingApp = mainapp;
end
I missed these originally because in the Matlab documentation, they were under the heading "Send Information to the Dialog Box", and I was only receiving information from the dialog box, not sending to it, so I thought I didn't need that.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!