Pass Panel components to function with App Designer

4 ビュー (過去 30 日間)
Dominik Müller
Dominik Müller 2020 年 11 月 27 日
回答済み: Mario Malic 2020 年 12 月 7 日
Hi folks,
I wonder if there's a way to pass the items of a panel in App Designer somehow like a struct.
Let's say I have a simple GUI with 3 spinners on a panel as shown above. Now I for example press a button which calls a function:
xy = myFunction(app.Panel);
What I want to do in the function is something like:
function xy = myFunction(Panel)
xy.a = Panel.Spinner.Value;
xy.b = Panel.Spinner2.Value;
xy.c = Panel.Spinner3.Value;
end
Is this possible?
Or do I have to pass every single value to my function?
I know I could do something like
xy = myFunction(app);
But I don't want to share the whole app data with my function. And in RL my panel not only contains 3 items.
Thanks in advance.

採用された回答

Mario Malic
Mario Malic 2020 年 12 月 7 日
Hello,
Yes, it's possible and what you posted should be working.
xy = myFunction(app.Panel);
If you inspect Panel component, the Spinner components will be in Children property of the Panel component. You can access each Spinner value by indexing into Children property. But, how does one know which dropdown comes first, is it the same order as in Component Browser section or the other, I am leaving you to check. You can also use the Tag property to distinguish between each Spinner.
app.Panel.Children(1).Value
If you want to use the values from dropdowns to do some calculations without changing panel options, maybe you should consider creating a struct that you will send to the function.
spinnerValues = struct('a', app.Spinner.Value, 'b', app.Spinner2.Value, 'c', app.Spinner3.Value)
xy = myFunction(spinnerValues);

その他の回答 (1 件)

Avratanu Biswas
Avratanu Biswas 2020 年 11 月 27 日
編集済み: Avratanu Biswas 2020 年 11 月 27 日
Hi ,
If I understood your question correctly, it is possible to pass all the components within an app ( as long as it is defined as a global property) . But you need to assign each values of the spinner separately in your case .
% for example
function xy = myFunction(app)
xy.a = app.Spinner.Value
xy.b = app.Spinner2.Value
xy.c = app.Spinner3.Value
end
  1 件のコメント
Dominik Müller
Dominik Müller 2020 年 11 月 30 日
This is exactly what I meant by
xy = myFunction(app);
But this is not what I want to do.
I only want the component's values placed on the panel to be passed to my function. And not all the app data.

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

カテゴリ

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