이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Passing Data between Apps
조회 수: 64 (최근 30일)
이전 댓글 표시
Eli Blumen
2020년 7월 7일
I'm making an app that calls up additional apps for input.
I've managed to do this successfully when all the variables are created in the second app.
However, I now need to make an app that has a drop down input that draws its items from the main app.
The guide on multi window apps is very good on showing how to "pass down" data, but not on "passing up" data.
I really need some help on this!
채택된 답변
Adam Danz
2020년 7월 7일
편집: Adam Danz
2022년 3월 15일
The documentation you mentioned, Creating Multiwindow Apps in App Designer, shows how to pass data both ways. If there's a section that is unclear, I'd be glad to help out with that step.
The main idea is to get access to the app handle for both apps. This answer also reviews some strategies.
Update: Here's a general idea of how to access external app data within a second app.
Step 1: Set up the Payroll app to receive one additional input which will be the app handle to the app that calls Payroll.
function startupFcn(app, callerApp)
Step 2: Within the Payroll app, delcare the callerApp as a private property.
It will look something like this
properties (access = private)
callerApp % handle to caller app
end
Step 3: Define callerApp in the Payroll startupFcn
function startupFcn(app, callerApp)
app.callerApp = callerApp;
end
Step 4: Access the callerApp data anywhere within your app.
function updatePayroll(app)
app.callerApp.PayDate
app.callerApp.PayName
end
댓글 수: 25
Eli Blumen
2020년 7월 8일
I was getting a little confused on how/if I needed to declare input arguments for the main app in order for it to pass data to the secondary app.
The link you posted is very helpful and seems to indicate that I can just call the handle for one of the apps to access its data.
Am I correct in understanding, that if a variable or function in one app is publicly declared, I can just call it? Otherwise, how would I call that variable up using the handle method?
Adam Danz
2020년 7월 8일
That's correct.
If you open app2 in app1,
app2 = mySecondApp;
Now App1 has all the handles to app2.
If you need app1 handles within app2, you can use one of the examples in the 2nd link in my answer.
Adam Danz
2020년 7월 9일
Eli Blumen's answer moved here as a comment.
Would this be a correct example for calling app1 from app2? Because I keep getting an error of not having enough input arguments.
function startupFcn(app, mainapp, PayDate, EmployeeName)
app.CallingApp = mainapp;
app.DateEditField.Value = Date;
app.EmployeeDropDown.Items = {mainapp.LastName,mainapp.FirstName};
app.EmployeeDropDown.Value = EmployeeName;
Adam Danz
2020년 7월 9일
I need to see the complete error message.
Do your app have inputs?
Have you defined CallingApp as a property?
Adam Danz
2020년 7월 10일
The error in your answer below shows that "Payroll" has "too many input arguments". In your previous comment, you mentioned that the error was "not enough input arguments".
It looks like you're proving 3 inputs.
Payroll(app,app.PayDate,app.PayName)
How many inputs does Payroll have? Can you share the line that defines Payroll?
Eli Blumen
2020년 7월 10일
Error using Payroll
Too many input arguments.
Error in TE566/PayEmployeeButtonPushed (line 347)
app.PayrollApp = Payroll(app,app.PayDate,app.PayName);
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 382)
Error while evaluating Button PrivateButtonPushedFcn.
CallingApp was defined as a property for this app (app3), I had also defined it for use in app2 - where it works fine.
The inputs for the app are a drop down selector, which reads data stored in the main app, and an edit field for the date.
Adam Danz
2020년 7월 10일
Is Payroll the app or is it a function?
If Payroll is a function, please share the function definition.
Eli Blumen
2020년 7월 11일
Payroll is the name of the called app. It would be the 3rd app.
It is supposed to take as an imput, a property (array) from the main app to use as items in a drop down selector.
It is supposed to output the value of that selector and an edit field.
Properties from first app I want to input into the third app:
EmployeeLastName = {'Doe'};
EmployeeFirstName = {'John'};
Current startup function of third app:
function startupFcn(app, mainapp, PayDate, EmployeeName)
app.CallingApp = mainapp;
app.DateEditField.Value = Date;
app.EmployeeDropDown.Items = {mainapp.LastName,mainapp.FirstName};
app.EmployeeDropDown.Value = EmployeeName;
end
Current passing function of third app in main app:
function updatePayroll(app, PayDate, EmployeeName)
app.PayDate = PayDate;
app.PayName = EmployeeName;
app.DatePaid = [app.DatePaid;app.PayDate];
app.Employee = [app.Employee;app.PayName];
app.MSL = [app.MSL;app.MonthlySalary];
app.BL = [app.BL;app.Bounce];
app.WFL = [app.WFL;app.Withholding_Federal];
app.WSL = [app.WSL;app.Withholding_State];
app.WSSNL = [app.WSSNL;app.Withholding_SocialSecurity];
app.WML = [app.WML;app.Withholding_Medicare];
app.WL = [app.WL;app.Withholding];
app.DL = [app.DL;app.Disbursment];
app.Withholding_Total = sum(app.Withholding);
app.Disbursment_Total = sum(app.Disbursment);
app.PayEmployeeButton.Enable = 'on';
end
Current calling function of third app in main app:
function PayEmployeeButtonPushed(app, event)
app.PayEmployeeButton.Enable = 'off';
app.PayrollApp = Payroll(app,app.PayDate,app.PayName);
end
I am a little confused by the documentation you referenced, because when I had previously called an app successfully before - its startup function had only declared input values generated by itself.
function startupFcn(app, mainapp, NewLastName, NewFirstName, NewAddressLine1, NewAddressLine2, NewCity, NewState, NewZip, NewSSN, NewYearlySalary)
app.CallingApp = mainapp;
app.LastNameEditField.Value = NewLastName;
app.FirstNameEditField.Value = NewFirstName;
app.AddressLine1EditField.Value = NewAddressLine1;
app.AddressLine2EditField.Value = NewAddressLine2;
app.CityEditField.Value = NewCity;
app.StateEditField.Value = NewState;
app.ZipEditField.Value = NewZip;
app.SSNEditField.Value = NewSSN;
app.YearlySalaryEditField.Value = NewYearlySalary;
end
When referenced in the main app, its passing function looked like this:
function updateEmployees(app, NewLastName, NewFirstName, NewAddressLine1, NewAddressLine2, NewCity, NewState, NewZip, NewSSN, NewYearlySalary)
app.NewLastName = NewLastName;
app.NewFirstName = NewFirstName;
app.NewAddressLine1 = NewAddressLine1;
app.NewAddressLine2 = NewAddressLine2;
app.NewCity = NewCity;
app.NewState = NewState;
app.NewZip = NewZip;
app.NewSSN = NewSSN;
app.NewYearlySalary = NewYearlySalary;
app.EmployeeLastName = [app.EmployeeLastName;app.NewLastName];
app.EmployeeFirstName = [app.EmployeeFirstName;app.NewFirstName];
app.EmployeeAddressLine1 = [app.EmployeeAddressLine1;NewAddressLine1];
app.EmployeeAddressLine2 = [app.EmployeeAddressLine2;app.NewAddressLine2];
app.EmployeeCity = [app.EmployeeCity;app.NewCity];
app.EmployeeState = [app.EmployeeState;app.NewState];
app.EmployeeZip = [app.EmployeeZip;app.NewZip];
app.SocialSecurityNumber = [app.SocialSecurityNumber;app.NewSSN];
app.Number_of_Withholdings = [app.Number_of_Withholdings;0];
app.YearlySalary = [app.YearlySalary;app.NewYearlySalary];
save('TE566.mlapp',app.EmployeeLastName,app.EmployeeFirstName,app.EmployeeAddressLine1,app.EmployeeAddressLine2,app.EmployeeCity,app.EmployeeState,app.EmployeeZip,app.SocialSecurityNumber,app.Number_of_Withholdings,app.YearlySalary);
app.AddEmployeesButton.Enable = 'on';
end
and its calling function in the main app looked like this:
function AddEmployeesButtonPushed(app, event)
app.AddEmployeesButton.Enable = 'off';
app.NewEmployeeApp = NewEmployee(app,app.NewLastName,app.NewFirstName,app.NewAddressLine1,app.NewAddressLine2,app.NewCity,app.NewState,app.NewZip,app.NewSSN,app.NewYearlySalary);
app.Tab.Title = 'Employees';
app.UITable.Data = table(app.EmployeeLastName,app.EmployeeFirstName,app.EmployeeAddressLine1,app.EmployeeAddressLine2,app.EmployeeCity,app.EmployeeState,app.EmployeeZip,app.SocialSecurityNumber,app.Number_of_Withholdings,app.YearlySalary);
app.UITable.ColumnName = {'Last Name' 'First Name' 'Address Line 1' 'Address Line 2' 'City' 'State' 'Zip Code' 'Social Security #' '# of Withholdings' 'Yearly Salary'};
end
I apologize for the wall of text. I am not terribly great at programming.
Adam Danz
2020년 7월 11일
I've added to my answer to show a general approach that is similar to yours but simpler. If you have trouble understanding any of the steps, I'd be happy to explain.
Eli Blumen
2020년 7월 19일
I got this to work with the Payroll function no problem - but when I try to do it for a different app, the data I want to get passed as drop down menu items doesn't show up.
code in second app called NewInvoice
% Code that executes after component creation
function startupFcn(app, callerApp, InvoiceDate, InvoiceCustomer, InvoiceQuantity)
app.callerApp = callerApp;
app.DateDatePicker.Value = InvoiceDate;
app.CustomerDropDown.Items = app.callerApp.CustomerCompanyName;
app.CustomerDropDown.Value = InvoiceCustomer;
app.UnitstoInvoiceEditField.Value = InvoiceQuantity;
data I am trying to refence in main app
CustomerCompanyName = {'Village Toy Shop';'Costco';'Wm. K. Walthers, Inc.';'Target';'Whistlestop Hobbies';'Amazon';'F.A.O Schwarz';'Michaels';'HobbyTown USA';'Odds n Ends'};
but I get the following

this is confusing because I passed the data to the dropdown items the same way as I had with the Payroll App
Adam Danz
2020년 7월 19일
Are you getting any error message? I don't have enough clues here to figure out what's going on. For example, is customer company name an independent variable and in which app? Why does it look like an independant variable in one line but an app property in another line?
Adam Danz
2020년 8월 1일
편집: Adam Danz
2020년 8월 1일
This line shows that it's a property in your app
app.CustomerDropDown.Items = app.callerApp.CustomerCompanyName;
but this line shows that's an independent variable
CustomerCompanyName = {'Village Toy Shop'; . . . ;'Odds n Ends'};
so there's an inconsistency unless the line above is defined within the properties section.
If that line is not defined within the properties section, you may need to define it this way.
app.callerApp.CustomerCompanyName = {'Village Toy Shop'; . . . ;'Odds n Ends'};
Jose María Olmos Pérez
2021년 2월 15일
Hi!
I am trying to follow your answer but I am completely lost...
I have two apps: plotMission (main app) and plotMission_segments (dialog app)
When I go to step 3
app.callerApp = callerApp
The following error appears:
Error using plotMission_segments/startupFcn (line 28)
Not enough input arguments.
No sourprise since tha variable callerApp is not defined... What variable should I use here? If I go with :
app.callerApp = plotMission
Then a new window appear...
Adam Danz
2021년 2월 15일
Based on your error message, it seems like your plotMission app is not passing it's handle to plotMission_segments (step 1).
Here's another answer to this same question that contains demo files to follow.
Jose María Olmos Pérez
2021년 2월 16일
편집: Jose María Olmos Pérez
2021년 2월 16일
Thank you for reply.
I have been trying with your examples, but once I close the second app, when I tried to call it in the main app, the handles are lost:
handle to deleted demo_SecondaryApp
Adam Danz
2021년 2월 16일
> once I close the second app, when I tried to call it in the main app, the handles are lost
That's expected. There's nothing in the documentation nor in my answers that suggests that this works after an app is closed. This doesn't store a copy of an app, it merely grants access to it's handles. If you delete a graphics object, it's handles become useless.
Jose María Olmos Pérez
2021년 2월 16일
You are totally right. My question is how to send variables from the dialog app to the main one (preferably once I close the dialog app)
What I have tried (without success) is to define a public function in the main app:
methods (Access = public)
function results = updateSegments(app,export_Data)
results = export_Data;
end
end
And in the dialog box, once I click on a push button:
results = updateSegments(app.mission,app.export_Data);
delete(app)
Being mission what you have called CallerApp.
But it is not working... Any ideas?
Adam Danz
2021년 2월 16일
> My question is how to send variables from the dialog app to the main one (preferably once I close the dialog app)
You can't. Once you close the app, there is no longer access to the app content.
Here are two approaches to consider,
1) Don't close the app, just make toggle its visibility (UIFigure > Visibility property). That way the app and all of its content still exists but is not visible until you turn it back on.
2) Before closing the app, store the data somewhere. You can send app1 to app2, app2 can store all of the needed data, and then app1 can close.
F S
2021년 9월 3일
Hi Adam,
I know the correct way to do this would be to ask a new question, but 2) of your last answer to Jose Maria describes exactely what i want to do! I just don't figure out how to do that. In fact, it is all I want app2 to do, to pass on the data from the spinners to app1, so it inserts them in the function the push button is running.
How do I send the data from app2 to app1, so that they are still there when I close app2?
Thank you, Florian
Adam Danz
2021년 9월 7일
편집: Adam Danz
2021년 9월 9일
@F S, I've been camping in the woods far from internet. I saw your question on this topic and answered it. 🌳🦝🌲
F S
2021년 9월 10일
@Adam Danz great! I hope you had a nice camping trip and enjoyed your time without internet! 🔥
Patrick Mirek
2022년 3월 15일
Hi Adam,
I followed the documentation exactly, but I'm getting an error which says "undefined function '_' for input arguments of type 'double'.", and it occurs when I call the function from the dialog box (in the example given in the documentation, it's the line: updateplot(app.CallingApp,app.EditField.Value,app.DropDown.Value);).
It seems that my secondary app doesn't have access to the public function created in the primary app. Any ideas on how to resolve this?
Adam Danz
2022년 3월 15일
> It seems that my secondary app doesn't have access to the public function created in the primary app. Any ideas on how to resolve this?
Is updateplot defined in your primary app or the secondary app?
Sharing the entire error message would also be helpful so I can see the function name(s).
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)