フィルターのクリア

multiple ui edit field clear using a callback

4 ビュー (過去 30 日間)
John Mark Odongo
John Mark Odongo 2018 年 10 月 24 日
コメント済み: John Mark Odongo 2018 年 10 月 25 日
Is it possible to change the value of 100 edit field(4 are text 96 are numeric) UI objects without having to write code for each one of them to clear their contents. I'm using the default names EditField_1 to 100.
  1 件のコメント
Stephen23
Stephen23 2018 年 10 月 25 日
編集済み: Stephen23 2018 年 10 月 25 日
" I'm using the default names EditField_1 to 100."
Ugh, this is such bad code design (not your fault, apparently this is just how appDesigner and GUIDE work). If you had simply written your own code (which I would recommend doing), then you could have just put all of those handles into one array H, and then all you would need is one set call:
set(H,'String','')
set even lets you set each object to a different value, read its help for more information.

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

採用された回答

Jan
Jan 2018 年 10 月 24 日
for k = 1:100
H = handles.(sprintf('EditField_%d', k));
set(H, 'String', sprintf('%g', rand));
end
I guessed you are working with GUIDE. It is not clear, which strings you want to insert. What is a "text" or "numeric" edit field? All these fields contain characters.
  4 件のコメント
Dennis
Dennis 2018 年 10 月 25 日
in appdesigner your handles are stored in app rather than in handles.
for k=1:100
H=app.(sprintf('EditField_%d',k)); %is there really a _ ?
if strcmp(get(H,'Type'),'uieditfield')
set(H,'Value','hi')
else
set(H,'Value',2)
end
end
Check the name of your first edit field, it might be EditField rather than EditField_1.
John Mark Odongo
John Mark Odongo 2018 年 10 月 25 日
Thanks this worked.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by