Undefined function error when passing data in multiwindow apps

조회 수: 2 (최근 30일)
Patrick Mirek
Patrick Mirek 2022년 3월 22일
댓글: Patrick Mirek 2022년 4월 13일
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

채택된 답변

Reshma Nerella
Reshma Nerella 2022년 4월 12일
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
Patrick Mirek
Patrick Mirek 2022년 4월 13일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by