How to Update Label Text from Custom Function in AppDesigner?

66 ビュー (過去 30 日間)
Arda Kayaalp
Arda Kayaalp 2022 年 10 月 3 日
コメント済み: Ergin Sezgin 2022 年 10 月 3 日
Hello everyone! I have custom analysing function that analyses the directory. I am calling this function from the main GUI app in AppDesigner. The function that I am calling from the main app has the following structure,
function analyse_result = analyse(path_dir)
objects = objects_in_dir(path_dir)
for ii = 1:length(objects)
do_something
end
end
Now I've added a label text on the gui and called ProgressLabel. What I want to do is to update this label inside the function body, so I've updated the function like so,
function analyse_result = analyse(path_dir,app.ProgressLabel.Text)
objects = objects_in_dir(path_dir)
for ii = 1:length(objects)
do_something
app.ProgressLabel.Text = sprintf("Iteration: %%u",(ii/length(objects))*100)
end
end
But when I'm calling this updated function from the main gui with added new variable, nothing changes on the text label. How can I solve this issuse?

採用された回答

Ergin Sezgin
Ergin Sezgin 2022 年 10 月 3 日
Hello Arda,
Try using drawnow to update figures and callbacks as the following:
function analyse_result = analyse(path_dir,app.ProgressLabel.Text)
objects = objects_in_dir(path_dir)
for ii = 1:length(objects)
do_something
app.ProgressLabel.Text = sprintf("Iteration: %%u",(ii/length(objects))*100)
drawnow
end
end
Same is necessary for other operations such as while loop terminations via a button.
  6 件のコメント
Arda Kayaalp
Arda Kayaalp 2022 年 10 月 3 日
Silly of me, I couldn't see the app structure. Thanks a lot, it worked!
Ergin Sezgin
Ergin Sezgin 2022 年 10 月 3 日
I'm happy that it worked, you are welcome.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by