フィルターのクリア

access data from one app in another app in appdesigner

33 ビュー (過去 30 日間)
Sampath Rachumallu
Sampath Rachumallu 2019 年 6 月 26 日
コメント済み: Adam Danz 2020 年 4 月 27 日
I want to access value of string entered in editbox of app1 in app2.This is the code i have written
%app1 code
%in a button_press callback in app1
val=app1.edit.Value;
setappdata(app1.Uifigure,val); %app1.UIfigure is the UIfigure name in app1
%app2 startup function
getappdata(app1.Uifigure,val);
i am getting error like
The property 'Uifigure' in class 'app1' must be accessed from a class instance because it is not a Constant property
kindly help me to overcome to this error
thanks in advance

回答 (1 件)

Sampath Rachumallu
Sampath Rachumallu 2020 年 4 月 27 日
Found the solution. Pasting it here for reference. In app designer we can acess an app data using 'app' handle. In the above case we can store the app handle of app1 in its StartupFcn in a global variable:
%Startup function of app1
function startupFcn(app)
global app1_handle=app;
end
%Button press callback function in app2
function buttonpress_callback(app)
global app1_handle;
text_entered=app1_handle.edit.Value; %Where edit the edit_field id used in app1
end
  1 件のコメント
Adam Danz
Adam Danz 2020 年 4 月 27 日
Be careful with global variables. They usually cause problems and area almost always avoidable.
To have access to the app handle anywhere within your app, set the app1_handle variable as a private (or public) property of your app. Here are instructions: https://www.mathworks.com/help/matlab/creating_guis/share-data-across-callbacks-in-app-designer.html

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by