How to find checkboxes in panel component in MATLAB app designer?

16 ビュー (過去 30 日間)
Kevin Gjoni
Kevin Gjoni 2023 年 1 月 27 日
コメント済み: Cris LaPierre 2023 年 1 月 28 日
% Find all the checkbox objects belonging to features
checkboxes = findobj(app.features, 'Style', 'checkbox');
In this code I'm trying to find all checkboxes that are in the panel "app.features". I don't get an error message, but I can't find any objects either. I get an 0x0 GraphicsPlaceholder. I only want to find the checkboxes that are in this panel, not in the whole app. How do I do this?
I attached the app, the section I'm talking about is in callbackfunction btnDrawButtonPushed(app, event).

採用された回答

Cris LaPierre
Cris LaPierre 2023 年 1 月 28 日
Try this instead
checkboxes = findall(app.features,'type','uicheckbox');
  2 件のコメント
Kevin Gjoni
Kevin Gjoni 2023 年 1 月 28 日
Now i get an error further down in my code:
% Initialize an empty cell array to store the names of the selected checkboxes
selected_names = {};
% Loop through the checkboxes and check which ones are selected
for i=1:numel(checkboxes)
if get(checkboxes(i), 'Value') == 1
% If the checkbox is selected, add its name to the cell array
selected_names{end+1} = get(checkboxes(i), 'String');
end
end
it says
Unrecognized property String for class CheckBox.
I want to store the names of only the selected checkboxes as I need them for something else in my code.
Cris LaPierre
Cris LaPierre 2023 年 1 月 28 日
As the message states, there is no String property for checkboxes. The checkbox properties documentation page contains a list of all the properties of a checkbox. There, you will see the property name is 'Text' instead of 'String'.
Try this instead.
selected_names{end+1} = checkboxes(i).Text;

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by