How to recover check box value?

12 ビュー (過去 30 日間)
Jean-Hugues LE GALLOU
Jean-Hugues LE GALLOU 2021 年 4 月 28 日
回答済み: Jean-Hugues LE GALLOU 2021 年 5 月 3 日
Hello,
Is it possible to get a value from a checkbox in a non visible figure. What would be the right instruction to get its value?
HIM(1)= figure ( ... 'visible','off'),
creation of the checkbox cb(1)
Call the value of cb(1)
treatment_cb=get(cb(1),'value'); does not work
Thanks for your answer
  2 件のコメント
Matt J
Matt J 2021 年 4 月 28 日
It should ...
Jan
Jan 2021 年 4 月 28 日
Please explain "does not work" with any details. The command should work actually, so it is important, what exactly you observe.

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

回答 (2 件)

Benjamin Großmann
Benjamin Großmann 2021 年 4 月 28 日
編集済み: Benjamin Großmann 2021 年 4 月 28 日
get(chkBox, 'Value') as well as chkBox.Value should work with visible and invisible uifigures equally.
% Create invisible uifigure
hmi = uifigure('Visible', 'Off');
% add checkbox to uifigure
chkBox = uicheckbox(hmi);
% Message string for anonymous helper function
msgStr = 'Checkbox value before set:';
% Anonymous helper function printChkBoxStatus to print the checkbox status
printChkBoxStatus = @() fprintf('%s %d\n', msgStr, get(chkBox, 'Value'));
% print the checkbox status
printChkBoxStatus()
% set the checkbox status to true ("checked")
set(chkBox, 'Value', true);
% print the checkbox status again
printChkBoxStatus()

Jean-Hugues LE GALLOU
Jean-Hugues LE GALLOU 2021 年 5 月 3 日
Hello,
Your code works.
I must have messed up my writing.
Thanks for your help
Sincerely

カテゴリ

Help Center および File ExchangeDevelop uifigure-Based Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by